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

Commit

Permalink
test(helpers): add tests to convert environment variable to int
Browse files Browse the repository at this point in the history
add tests to convert environment variable to int
  • Loading branch information
danbucholtz committed Feb 23, 2017
1 parent 2e2a647 commit b60a6f0
Showing 1 changed file with 54 additions and 8 deletions.
62 changes: 54 additions & 8 deletions src/util/helpers.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,64 @@
import * as helpers from './helpers';

let originalEnv: any = process.env;
describe('helpers', () => {

beforeEach(() => {
originalEnv = process.env;
process.env = {};
});

afterEach(() => {
process.env = originalEnv;
});

describe('getIntPropertyValue', () => {
it('should return an int', () => {
// arrange
const propertyName = 'test';
const propertyValue = '3000';
process.env[propertyName] = propertyValue;

// act
const result = helpers.getIntPropertyValue(propertyName);

// assert
expect(result).toEqual(3000);
});

it('should round to an int', () => {
// arrange
const propertyName = 'test';
const propertyValue = '3000.03';
process.env[propertyName] = propertyValue;

// act
const result = helpers.getIntPropertyValue(propertyName);

// assert
expect(result).toEqual(3000);
});

it('should round to a NaN', () => {
// arrange
const propertyName = 'test';
const propertyValue = 'tacos';
process.env[propertyName] = propertyValue;

// act
const result = helpers.getIntPropertyValue(propertyName);

// assert
expect(result).toEqual(NaN);
});
});

describe('getBooleanPropertyValue', () => {
it('should return true when value is "true"', () => {
// arrange
const propertyName = 'test';
const propertyValue = 'true';
let environment: any = { };
environment[propertyName] = propertyValue;
process.env = environment;
process.env[propertyName] = propertyValue;
// act
const result = helpers.getBooleanPropertyValue(propertyName);
// assert
Expand All @@ -18,8 +68,6 @@ describe('helpers', () => {
it('should return false when value is undefined/null', () => {
// arrange
const propertyName = 'test';
let environment: any = { };
process.env = environment;
// act
const result = helpers.getBooleanPropertyValue(propertyName);
// assert
Expand All @@ -30,9 +78,7 @@ describe('helpers', () => {
// arrange
const propertyName = 'test';
const propertyValue = 'taco';
let environment: any = { };
environment[propertyName] = propertyValue;
process.env = environment;
process.env[propertyName] = propertyValue;
// act
const result = helpers.getBooleanPropertyValue(propertyName);
// assert
Expand Down

0 comments on commit b60a6f0

Please sign in to comment.