Skip to content

Commit 4e27947

Browse files
committed
Add tests for reset
1 parent e5eb4d4 commit 4e27947

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

test/spec/asyncVersioningSpec.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,30 @@ describe("JSONPatchQueue instance", function () {
1212
expect(queue.remoteVersion).toEqual(0);
1313
});
1414

15+
describe('when reset', function () {
16+
it('should set remote version to value given', function () {
17+
var queue = new JSONPatchQueue(["/local","/remote"],function(){});
18+
queue.reset({}, {local: 1, remote: 2});
19+
expect(queue.remoteVersion).toEqual(2);
20+
});
21+
it('should set remote version to value given even with complex version path', function () {
22+
var queue = new JSONPatchQueue(["/v/local","/v/remote"],function(){});
23+
queue.reset({}, {v: {local: 1, remote: 2}});
24+
expect(queue.remoteVersion).toEqual(2);
25+
});
26+
it('should apply big replace patch to obj', function () {
27+
var appliedPatch;
28+
var queue = new JSONPatchQueue(["/local","/remote"],function apply(obj, patches){
29+
appliedPatch = patches;
30+
});
31+
var newState = {local: 1, remote: 2, name: 'newname'};
32+
33+
queue.reset({}, newState);
34+
35+
expect(appliedPatch).toEqual([{op: 'replace', path: '', value: newState}]);
36+
});
37+
});
38+
1539
describe("when receives a Versioned JSON Patch", function () {
1640
var queue, applyPatch;
1741
beforeEach(function () {

test/spec/synchronousVersioningSpec.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,30 @@ describe("JSONPatchQueueSynchronous instance", function () {
1010
expect(queue.version).toEqual(0);
1111
});
1212

13+
describe('when reset', function () {
14+
it('should set remote version to value given', function () {
15+
var queue = new JSONPatchQueueSynchronous("/version",function(){});
16+
queue.reset({}, {version: 1});
17+
expect(queue.version).toEqual(1);
18+
});
19+
it('should set remote version to value given even with complex version path', function () {
20+
var queue = new JSONPatchQueueSynchronous("/v/version",function(){});
21+
queue.reset({}, {v: {version: 1}});
22+
expect(queue.version).toEqual(1);
23+
});
24+
it('should apply big replace patch to obj', function () {
25+
var appliedPatch;
26+
var queue = new JSONPatchQueueSynchronous("/version",function apply(obj, patches){
27+
appliedPatch = patches;
28+
});
29+
var newState = {version: 1, name: 'newname'};
30+
31+
queue.reset({}, newState);
32+
33+
expect(appliedPatch).toEqual([{op: 'replace', path: '', value: newState}]);
34+
});
35+
});
36+
1337
describe("when receives a Versioned JSON Patch", function () {
1438
var queue, applyPatch;
1539
beforeEach(function () {

0 commit comments

Comments
 (0)