Skip to content

Commit

Permalink
fix: Dot notation on JSON arrays doesn't work on PushStatus offset …
Browse files Browse the repository at this point in the history
…fields (#2194)
  • Loading branch information
dplewis committed Jun 28, 2024
1 parent f7c50e9 commit e0eb6f0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/ObjectStateMutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ export function commitServerChanges(
typeof val === 'object' &&
!Array.isArray(val) &&
Object.keys(val).length > 0 &&
Object.keys(val).some(k => !isNaN(parseInt(k)))
Object.keys(val).some(k => !isNaN(parseInt(k))) &&
!['sentPerUTCOffset', 'failedPerUTCOffset'].includes(attr)
) {
val = Object.values(val);
}
Expand Down
18 changes: 18 additions & 0 deletions src/__tests__/ObjectStateMutations-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,24 @@ describe('ObjectStateMutations', () => {
expect(objectCache).toEqual({ items: '[{"count":20},{"count":5}]' });
});

it('can commit json array with PushStatus offset fields', () => {
const serverData = {};
const objectCache = {};
ObjectStateMutations.commitServerChanges(serverData, objectCache, {
sentPerUTCOffset: { '1': { count: 20 } },
failedPerUTCOffset: { '5': { count: 25 } },
});
// Should not transform to an array
expect(serverData).toEqual({
sentPerUTCOffset: { '1': { count: 20 } },
failedPerUTCOffset: { '5': { count: 25 } },
});
expect(objectCache).toEqual({
sentPerUTCOffset: '{"1":{"count":20}}',
failedPerUTCOffset: '{"5":{"count":25}}',
});
});

it('can generate a default state for implementations', () => {
expect(ObjectStateMutations.defaultState()).toEqual({
serverData: {},
Expand Down

0 comments on commit e0eb6f0

Please sign in to comment.