Skip to content

Commit e0eb6f0

Browse files
authored
fix: Dot notation on JSON arrays doesn't work on PushStatus offset fields (#2194)
1 parent f7c50e9 commit e0eb6f0

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/ObjectStateMutations.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,8 @@ export function commitServerChanges(
191191
typeof val === 'object' &&
192192
!Array.isArray(val) &&
193193
Object.keys(val).length > 0 &&
194-
Object.keys(val).some(k => !isNaN(parseInt(k)))
194+
Object.keys(val).some(k => !isNaN(parseInt(k))) &&
195+
!['sentPerUTCOffset', 'failedPerUTCOffset'].includes(attr)
195196
) {
196197
val = Object.values(val);
197198
}

src/__tests__/ObjectStateMutations-test.js

+18
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,24 @@ describe('ObjectStateMutations', () => {
323323
expect(objectCache).toEqual({ items: '[{"count":20},{"count":5}]' });
324324
});
325325

326+
it('can commit json array with PushStatus offset fields', () => {
327+
const serverData = {};
328+
const objectCache = {};
329+
ObjectStateMutations.commitServerChanges(serverData, objectCache, {
330+
sentPerUTCOffset: { '1': { count: 20 } },
331+
failedPerUTCOffset: { '5': { count: 25 } },
332+
});
333+
// Should not transform to an array
334+
expect(serverData).toEqual({
335+
sentPerUTCOffset: { '1': { count: 20 } },
336+
failedPerUTCOffset: { '5': { count: 25 } },
337+
});
338+
expect(objectCache).toEqual({
339+
sentPerUTCOffset: '{"1":{"count":20}}',
340+
failedPerUTCOffset: '{"5":{"count":25}}',
341+
});
342+
});
343+
326344
it('can generate a default state for implementations', () => {
327345
expect(ObjectStateMutations.defaultState()).toEqual({
328346
serverData: {},

0 commit comments

Comments
 (0)