|
1 |
| -'use strict'; |
2 |
| - |
3 |
| -var expect = require('chai').expect; |
4 |
| - |
5 |
| -var camelCaseKeys = require('../'); |
6 |
| - |
7 |
| -describe('Nested keys within arrays and objects are camelCased', function() { |
8 |
| - |
9 |
| - it('Should camelCase all Snake keys', function() { |
10 |
| - |
11 |
| - var anotherCamelWithTheHump = camelCaseKeys({ |
12 |
| - 'test-1': 123, |
13 |
| - 'test-Two': [{ |
14 |
| - 'test-three': { |
15 |
| - 'test-FOUR': [{ |
16 |
| - 'test-five': [{ |
17 |
| - 'test-six': { |
18 |
| - 'test-seven': [1, 4, [1, 2, '3', 'four', 'five-one']] |
19 |
| - } |
20 |
| - }] |
21 |
| - }] |
22 |
| - } |
23 |
| - }] |
24 |
| - }); |
25 |
| - |
26 |
| - expect(anotherCamelWithTheHump).deep.equals({ |
27 |
| - test1: 123, |
28 |
| - testTwo: [{ |
29 |
| - testThree: { |
30 |
| - testFOUR: [{ |
31 |
| - testFive: [{ |
32 |
| - testSix: { |
33 |
| - testSeven: [1, 4, [1, 2, '3', 'four', 'five-one']] |
34 |
| - } |
35 |
| - }] |
36 |
| - }] |
37 |
| - } |
38 |
| - }] |
39 |
| - }); |
40 |
| - |
41 |
| - }); |
42 |
| - |
43 |
| - it('Should camelCase all Snake keys - with nulls', function() { |
44 |
| - |
45 |
| - var anotherCamelWithTheHump = camelCaseKeys({ |
46 |
| - 'test-1': null, |
47 |
| - 'test-Two': [{ |
48 |
| - 'test-three': { |
49 |
| - 'test-FOUR': [{ |
50 |
| - 'test-five': [{ |
51 |
| - 'test-six': { |
52 |
| - 'test-seven': [1, 4, [1, undefined, '3', 'four', 'five-one']] |
53 |
| - } |
54 |
| - }] |
55 |
| - }] |
56 |
| - } |
57 |
| - }] |
58 |
| - }); |
59 |
| - |
60 |
| - expect(anotherCamelWithTheHump).deep.equals({ |
61 |
| - test1: null, |
62 |
| - testTwo: [{ |
63 |
| - testThree: { |
64 |
| - testFOUR: [{ |
65 |
| - testFive: [{ |
66 |
| - testSix: { |
67 |
| - testSeven: [1, 4, [1, undefined, '3', 'four', 'five-one']] |
68 |
| - } |
69 |
| - }] |
70 |
| - }] |
71 |
| - } |
72 |
| - }] |
73 |
| - }); |
74 |
| - |
75 |
| - }); |
76 |
| - |
77 |
| - it('Should handle date values', function(){ |
78 |
| - |
79 |
| - var expected = { |
80 |
| - createdAt:'2015-09-24T13:44:41.553Z' |
81 |
| - }; |
82 |
| - |
83 |
| - var input = { |
84 |
| - created_at:'2015-09-24T13:44:41.553Z' |
85 |
| - }; |
86 |
| - |
87 |
| - expect(expected).deep.equals(camelCaseKeys(input)); |
88 |
| - |
89 |
| - }); |
90 |
| - |
91 |
| - it('Should handle date within objects', function(){ |
92 |
| - var expected = { |
93 |
| - store: { |
94 |
| - total: '210.00', |
95 |
| - count: '1' |
96 |
| - }, |
97 |
| - user: { |
98 |
| - lastOrder: { |
99 |
| - id: '1', |
100 |
| - status: 3, |
101 |
| - userId: '82', |
102 |
| - customerId: '6100', |
103 |
| - storeId: '12', |
104 |
| - externalId: '2015-09-22T14:38:01.201Z', |
105 |
| - createdAt: '2015-09-24T13:44:41.553Z', |
106 |
| - price: '210.00', |
107 |
| - pricePaid: '210.00', |
108 |
| - currencyIso: 'GBP', |
109 |
| - details: null, |
110 |
| - deleted: false |
111 |
| - } |
112 |
| - } |
113 |
| - }; |
114 |
| - |
115 |
| - var input = { |
116 |
| - store: { |
117 |
| - total: '210.00', |
118 |
| - count: '1' |
119 |
| - }, |
120 |
| - user: { |
121 |
| - lastOrder: { |
122 |
| - id: '1', |
123 |
| - status: 3, |
124 |
| - user_id: '82', |
125 |
| - customer_id: '6100', |
126 |
| - store_id: '12', |
127 |
| - external_id: '2015-09-22T14:38:01.201Z', |
128 |
| - created_at: '2015-09-24T13:44:41.553Z', |
129 |
| - price: '210.00', |
130 |
| - price_paid: '210.00', |
131 |
| - currency_iso: 'GBP', |
132 |
| - details: null, |
133 |
| - deleted: false |
134 |
| - } |
135 |
| - } |
136 |
| - }; |
137 |
| - |
138 |
| - expect(expected).deep.equals(camelCaseKeys(input)); |
139 |
| - |
140 |
| - |
141 |
| - }); |
| 1 | +import {expect} from 'chai'; |
| 2 | + |
| 3 | +const camelCaseKeys = require('../'); |
| 4 | + |
| 5 | +describe('Nested keys within arrays and objects are camelCased', () => { |
| 6 | + |
| 7 | + it('Should camelCase all Snake keys', () => { |
| 8 | + |
| 9 | + const anotherCamelWithTheHump = camelCaseKeys({ |
| 10 | + 'test-1': 123, |
| 11 | + 'test-Two': [{ |
| 12 | + 'test-three': { |
| 13 | + 'test-FOUR': [{ |
| 14 | + 'test-five': [{ |
| 15 | + 'test-six': { |
| 16 | + 'test-seven': [1, 4, [1, 2, '3', 'four', 'five-one']] |
| 17 | + } |
| 18 | + }] |
| 19 | + }] |
| 20 | + } |
| 21 | + }] |
| 22 | + }); |
| 23 | + |
| 24 | + expect(anotherCamelWithTheHump).deep.equals({ |
| 25 | + test1: 123, |
| 26 | + testTwo: [{ |
| 27 | + testThree: { |
| 28 | + testFOUR: [{ |
| 29 | + testFive: [{ |
| 30 | + testSix: { |
| 31 | + testSeven: [1, 4, [1, 2, '3', 'four', 'five-one']] |
| 32 | + } |
| 33 | + }] |
| 34 | + }] |
| 35 | + } |
| 36 | + }] |
| 37 | + }); |
| 38 | + |
| 39 | + }); |
| 40 | + |
| 41 | + it('Should camelCase all Snake keys - with nulls', () => { |
| 42 | + |
| 43 | + const anotherCamelWithTheHump = camelCaseKeys({ |
| 44 | + 'test-1': null, |
| 45 | + 'test-Two': [{ |
| 46 | + 'test-three': { |
| 47 | + 'test-FOUR': [{ |
| 48 | + 'test-five': [{ |
| 49 | + 'test-six': { |
| 50 | + 'test-seven': [1, 4, [1, undefined, '3', 'four', 'five-one']] |
| 51 | + } |
| 52 | + }] |
| 53 | + }] |
| 54 | + } |
| 55 | + }] |
| 56 | + }); |
| 57 | + |
| 58 | + expect(anotherCamelWithTheHump).deep.equals({ |
| 59 | + test1: null, |
| 60 | + testTwo: [{ |
| 61 | + testThree: { |
| 62 | + testFOUR: [{ |
| 63 | + testFive: [{ |
| 64 | + testSix: { |
| 65 | + testSeven: [1, 4, [1, undefined, '3', 'four', 'five-one']] |
| 66 | + } |
| 67 | + }] |
| 68 | + }] |
| 69 | + } |
| 70 | + }] |
| 71 | + }); |
| 72 | + |
| 73 | + }); |
| 74 | + |
| 75 | + it('Should handle date values', () => { |
| 76 | + |
| 77 | + const expected = { |
| 78 | + createdAt: '2015-09-24T13:44:41.553Z' |
| 79 | + }; |
| 80 | + |
| 81 | + const input = { |
| 82 | + created_at: '2015-09-24T13:44:41.553Z' |
| 83 | + }; |
| 84 | + |
| 85 | + expect(expected).deep.equals(camelCaseKeys(input)); |
| 86 | + |
| 87 | + }); |
| 88 | + |
| 89 | + it('Should handle date within objects', () => { |
| 90 | + const expected = { |
| 91 | + store: { |
| 92 | + total: '210.00', |
| 93 | + count: '1' |
| 94 | + }, |
| 95 | + user: { |
| 96 | + lastOrder: { |
| 97 | + id: '1', |
| 98 | + status: 3, |
| 99 | + userId: '82', |
| 100 | + customerId: '6100', |
| 101 | + storeId: '12', |
| 102 | + externalId: '2015-09-22T14:38:01.201Z', |
| 103 | + createdAt: '2015-09-24T13:44:41.553Z', |
| 104 | + price: '210.00', |
| 105 | + pricePaid: '210.00', |
| 106 | + currencyIso: 'GBP', |
| 107 | + details: null, |
| 108 | + deleted: false |
| 109 | + } |
| 110 | + } |
| 111 | + }; |
| 112 | + |
| 113 | + const input = { |
| 114 | + store: { |
| 115 | + total: '210.00', |
| 116 | + count: '1' |
| 117 | + }, |
| 118 | + user: { |
| 119 | + lastOrder: { |
| 120 | + id: '1', |
| 121 | + status: 3, |
| 122 | + user_id: '82', |
| 123 | + customer_id: '6100', |
| 124 | + store_id: '12', |
| 125 | + external_id: '2015-09-22T14:38:01.201Z', |
| 126 | + created_at: '2015-09-24T13:44:41.553Z', |
| 127 | + price: '210.00', |
| 128 | + price_paid: '210.00', |
| 129 | + currency_iso: 'GBP', |
| 130 | + details: null, |
| 131 | + deleted: false |
| 132 | + } |
| 133 | + } |
| 134 | + }; |
| 135 | + |
| 136 | + expect(expected).deep.equals(camelCaseKeys(input)); |
| 137 | + |
| 138 | + |
| 139 | + }); |
142 | 140 |
|
143 | 141 | });
|
0 commit comments