diff options
Diffstat (limited to 'test/utils/KeyMirror.test.js')
-rw-r--r-- | test/utils/KeyMirror.test.js | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/test/utils/KeyMirror.test.js b/test/utils/KeyMirror.test.js new file mode 100644 index 0000000..22f6ff5 --- /dev/null +++ b/test/utils/KeyMirror.test.js @@ -0,0 +1,79 @@ +import keyMirror from 'utils/KeyMirror.js'; + +describe('KeyMirror', () => { + it('valid key mirror with nulls', () => { + const obj = { + TIER_SUPPORT: null, + INVENTORY: null, + VNF_SEARCH: null + } + const mirror = keyMirror(obj); + + for (let key in obj) { + expect(mirror).toHaveProperty(key); + expect(JSON.stringify(mirror[key])).toBe(JSON.stringify(Symbol(key))); + } + }); + + it('valid key mirror with undefined', () => { + const obj = { + TIER_SUPPORT: undefined, + INVENTORY: undefined, + VNF_SEARCH: undefined + } + const mirror = keyMirror(obj); + + for (let key in obj) { + expect(mirror).toHaveProperty(key); + expect(JSON.stringify(mirror[key])).toBe(JSON.stringify(Symbol(key))); + } + }); + + it('valid key mirror with values', () => { + let preMirrorList = { + TIER_SUPPORT: 'tier support', + INVENTORY: 'inventory', + VNF_SEARCH: 'vnf search' + }; + const mirror = keyMirror(preMirrorList); + + for (let key in preMirrorList) { + expect(mirror).toHaveProperty(key); + expect(JSON.stringify(mirror[key])).toBe(JSON.stringify(preMirrorList[key])); + } + }); + + it('valid key mirror with objects', () => { + let preMirrorList = { + TIER_SUPPORT: { + name: 'tier support' + }, + INVENTORY: { + name: 'inventory' + }, + VNF_SEARCH: { + name: 'vnf search' + } + }; + const mirror = keyMirror(preMirrorList); + + for (let key in preMirrorList) { + expect(mirror).toHaveProperty(key); + expect(JSON.stringify(mirror[key])).toBe(JSON.stringify(preMirrorList[key])); + } + }); + + it('invalid key mirror', () => { + let preMirrorList = [ + 'tier support', + 'inventory', + 'vnf search' + ] + const mirror = () => { + keyMirror(preMirrorList); + } + + expect(mirror).toThrow(Error); + expect(mirror).toThrowError('keyMirror(...): Argument must be an object.'); + }); +}) |