-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #280 from zalando-incubator/web-ui-fix-boolean-env…
…-variable web-ui: fix boolean as string ENV variables parsing
- Loading branch information
Showing
3 changed files
with
61 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'use strict'; | ||
|
||
const {stringToBool} = require('../util'); | ||
|
||
|
||
describe('server.util', () => { | ||
describe('stringToBool', () => { | ||
test('transform "false" values into real booleans while keeping other values as they are', () => { | ||
expect(stringToBool({ | ||
foo: 'false', | ||
bar: false | ||
})).toEqual({ | ||
foo: false, | ||
bar: false | ||
}); | ||
}); | ||
|
||
test('transform "true" values into real booleans while keeping other values as they are', () => { | ||
expect(stringToBool({ | ||
foo: 'true', | ||
bar: 'true', | ||
john: 'doe' | ||
})).toEqual({ | ||
foo: true, | ||
bar: true, | ||
john: 'doe' | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
'use strict'; | ||
|
||
/** | ||
* Dummy function to transform object that contains | ||
* boolean values expressed as strings (eg. 'true' or 'false') | ||
* in real boolean values. Doesn't traverse the object tree. | ||
* | ||
* @param {Object} object | ||
* @return {Object} | ||
*/ | ||
function stringToBool (object) { | ||
return Object.keys(object).reduce((acc, key) => { | ||
if (object[key] === 'true') { | ||
acc[key] = true; | ||
} else if (object[key] === 'false') { | ||
acc[key] = false; | ||
} else { | ||
acc[key] = object[key]; | ||
} | ||
return acc; | ||
}, {}); | ||
} | ||
|
||
module.exports = { | ||
stringToBool | ||
}; |