forked from ltwlf/json-diff-ts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathatomizeChangeset.test.ts
39 lines (30 loc) · 1.23 KB
/
atomizeChangeset.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { diff, atomizeChangeset } from '../src/jsonDiff';
describe('atomizeChangeset', () => {
test('when JSON path segements contain periods', (done) => {
const oldObject = { 'a.b': 1 };
const newObject = { 'a.b': 2 };
const actual = atomizeChangeset(diff(oldObject, newObject))[0];
expect(actual.path).toBe('$[a.b]');
done();
});
test('when JSON path segments containing periods use embedded keys', (done) => {
const oldObject = { 'a.b': [{ c: 1 }] };
const newObject = { 'a.b': [{ c: 2 }] };
const diffs = diff(oldObject, newObject, { embeddedObjKeys: { 'a.b': 'c' } });
const actual = atomizeChangeset(diffs);
expect(actual.length).toBe(2);
expect(actual[0].path).toBe('$[a.b]');
expect(actual[1].path).toBe("$[a.b][?(@.c=='1')]");
done();
});
test('when embedded key name contains periods', (done) => {
const oldObject = { a: [{ b: 1, 'c.d': 10 }] };
const newObject = { a: [{ b: 2, 'c.d': 20 }] };
const diffs = diff(oldObject, newObject, { embeddedObjKeys: { a: 'c.d' } });
const actual = atomizeChangeset(diffs);
expect(actual.length).toBe(2);
expect(actual[0].path).toBe('$.a');
expect(actual[1].path).toBe("$.a[?(@[c.d]=='10')]");
done();
});
});