import convertKeysToLowerCase from '../src/json-utils/convert-keys-lower-case'; describe('Testing lower case conversion of keys', () => { const testObj = { HelloWorld: 'helloWorld', 'Hello': 'HelloWorld', nestedStruct: { nesTed1: 'nested1', nestedLev2: { nesTED3: 100 } }, style: { backgroundColor: '#ff00FF', fontWeight: 'BOLD' }, headerStyle: { backgroundAlpha: 0.8, backgroundColor: '#ff0000' } }; it('Nested structure with ignore flag', () => { const returnObj = { helloworld: 'helloWorld', hello: 'HelloWorld', nestedstruct: { nested1: 'nested1', nestedlev2: { nested3: 100 } }, style: { backgroundColor: '#ff00FF', fontWeight: 'BOLD' }, headerstyle: { backgroundAlpha: 0.8, backgroundColor: '#ff0000' } }; expect(JSON.stringify(convertKeysToLowerCase(testObj, ['style', 'headerstyle']))).toBe(JSON.stringify(returnObj)); }); }); describe('Testing lower case conversion of values', () => { const testObj = { HelloWorld: 'helloWorld', 'Hello': 'HelloWorld', nestedStruct: { nesTed1: 'Nested1', nestedLev2: { nesTED3: 100 } }, style: { backgroundColor: '#ff00FF', fontWeight: 'BOLD' }, headerStyle: { backgroundAlpha: 0.8, backgroundColor: '#ff0000' } }; it('Converts the mentioned values to lower case', () => { const returnObj = { helloworld: 'helloWorld', hello: 'helloworld', nestedstruct: { nested1: 'nested1', nestedlev2: { nested3: 100 } }, style: { backgroundColor: '#ff00FF', fontWeight: 'BOLD' }, headerstyle: { backgroundAlpha: 0.8, backgroundColor: '#ff0000' } }; expect(JSON.stringify(convertKeysToLowerCase(testObj, ['style', 'headerstyle'], ['hello', 'nested1']))).toBe(JSON.stringify(returnObj)); }); it('Converts the mentioned values to lower case but leaves rest of the values as it is', () => { const returnObj = { helloworld: 'helloWorld', hello: 'HelloWorld', nestedstruct: { nested1: 'nested1', nestedlev2: { nested3: 100 } }, style: { backgroundColor: '#ff00FF', fontWeight: 'BOLD' }, headerstyle: { backgroundAlpha: 0.8, backgroundColor: '#ff0000' } }; expect(JSON.stringify(convertKeysToLowerCase(testObj, ['style', 'headerstyle'], ['nested1']))).toBe(JSON.stringify(returnObj)); }); });