Skip to content
This repository was archived by the owner on May 1, 2020. It is now read-only.

Commit b60a6f0

Browse files
committed
test(helpers): add tests to convert environment variable to int
add tests to convert environment variable to int
1 parent 2e2a647 commit b60a6f0

File tree

1 file changed

+54
-8
lines changed

1 file changed

+54
-8
lines changed

src/util/helpers.spec.ts

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,64 @@
11
import * as helpers from './helpers';
22

3+
let originalEnv: any = process.env;
34
describe('helpers', () => {
5+
6+
beforeEach(() => {
7+
originalEnv = process.env;
8+
process.env = {};
9+
});
10+
11+
afterEach(() => {
12+
process.env = originalEnv;
13+
});
14+
15+
describe('getIntPropertyValue', () => {
16+
it('should return an int', () => {
17+
// arrange
18+
const propertyName = 'test';
19+
const propertyValue = '3000';
20+
process.env[propertyName] = propertyValue;
21+
22+
// act
23+
const result = helpers.getIntPropertyValue(propertyName);
24+
25+
// assert
26+
expect(result).toEqual(3000);
27+
});
28+
29+
it('should round to an int', () => {
30+
// arrange
31+
const propertyName = 'test';
32+
const propertyValue = '3000.03';
33+
process.env[propertyName] = propertyValue;
34+
35+
// act
36+
const result = helpers.getIntPropertyValue(propertyName);
37+
38+
// assert
39+
expect(result).toEqual(3000);
40+
});
41+
42+
it('should round to a NaN', () => {
43+
// arrange
44+
const propertyName = 'test';
45+
const propertyValue = 'tacos';
46+
process.env[propertyName] = propertyValue;
47+
48+
// act
49+
const result = helpers.getIntPropertyValue(propertyName);
50+
51+
// assert
52+
expect(result).toEqual(NaN);
53+
});
54+
});
55+
456
describe('getBooleanPropertyValue', () => {
557
it('should return true when value is "true"', () => {
658
// arrange
759
const propertyName = 'test';
860
const propertyValue = 'true';
9-
let environment: any = { };
10-
environment[propertyName] = propertyValue;
11-
process.env = environment;
61+
process.env[propertyName] = propertyValue;
1262
// act
1363
const result = helpers.getBooleanPropertyValue(propertyName);
1464
// assert
@@ -18,8 +68,6 @@ describe('helpers', () => {
1868
it('should return false when value is undefined/null', () => {
1969
// arrange
2070
const propertyName = 'test';
21-
let environment: any = { };
22-
process.env = environment;
2371
// act
2472
const result = helpers.getBooleanPropertyValue(propertyName);
2573
// assert
@@ -30,9 +78,7 @@ describe('helpers', () => {
3078
// arrange
3179
const propertyName = 'test';
3280
const propertyValue = 'taco';
33-
let environment: any = { };
34-
environment[propertyName] = propertyValue;
35-
process.env = environment;
81+
process.env[propertyName] = propertyValue;
3682
// act
3783
const result = helpers.getBooleanPropertyValue(propertyName);
3884
// assert

0 commit comments

Comments
 (0)