Skip to content

Commit 367dbf2

Browse files
committed
write tests
1 parent 7881ef8 commit 367dbf2

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

src/main/services/patcher/patch-verifier.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export class PatchVerifier {
7373
* @param patch
7474
* @returns the signed patch (to be sent to the server)
7575
*/
76-
public sign(patch: Patch) {
76+
public sign(patch: Patch): SignedPatch {
7777
return patch.map((op) => this.signOperation(op));
7878
}
7979

src/tests/unit/services/patcher/patcher-reducer-test.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,27 @@ describe('test patcher reducer.', () => {
1616

1717
test('calls given transform function for applying the patch.', () => {
1818
const cb = jest.fn((x) => ({ y: x.x }));
19+
const inv = (x: any) => ({ x: x.y });
1920

2021
const patcher = new Patcher();
2122
patcher.initialize({});
2223

23-
const reducer = createPatcherReducer(patcher, { transform: cb });
24+
const reducer = createPatcherReducer(patcher, { transform: cb, transformInverse: inv });
2425
const nextState = reducer({ y: 41 }, PatcherRepository.patch([{ op: 'add', path: '/x', value: 42 }]));
2526

2627
expect(nextState).toEqual({ y: 42 });
2728
});
2829

30+
test('passes the state to the patcher.', () => {
31+
const patcher = new Patcher();
32+
patcher.initialize({});
33+
34+
const reducer = createPatcherReducer(patcher);
35+
const nextState = reducer({ y: 41 }, PatcherRepository.patch([{ op: 'add', path: '/x', value: 42 }]));
36+
37+
expect(nextState).toEqual({ x: 42, y: 41 });
38+
});
39+
2940
test('calls given merge function for applying the patch.', () => {
3041
const cb = jest.fn((x, y) => ({ ...x, ...y }));
3142

src/tests/unit/services/patcher/patcher-test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,4 +170,11 @@ describe('patcher class.', () => {
170170
const res3 = patcher.patch([{ op: 'replace', path: '/x', value: 46, hash: '123' }]);
171171
expect(res3.patched).toBe(false);
172172
});
173+
174+
test('can update snapshot on patch.', () => {
175+
const patcher = new Patcher();
176+
patcher.initialize({ x: 42, y: 43 });
177+
const res = patcher.patch([{ op: 'replace', path: '/x', value: 44 }], { y: 45 });
178+
expect(res.result).toEqual({ x: 44, y: 45 });
179+
});
173180
});

0 commit comments

Comments
 (0)