Skip to content

Commit 4ee3431

Browse files
committed
Add tests for merging nodes with empty bodies
1 parent 1a8d3f9 commit 4ee3431

File tree

1 file changed

+102
-3
lines changed

1 file changed

+102
-3
lines changed

test/unit/sync.test.mjs

Lines changed: 102 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -840,8 +840,74 @@ describe("Sync", function() {
840840
});
841841
});
842842

843-
describe("#autoMerge", function() {
844-
describe("when node was updated", function() {
843+
describe.only("#autoMerge", function() {
844+
describe("new node", function() {
845+
beforeEach(function() {
846+
this.node = {
847+
path: "foo",
848+
common: {},
849+
remote: { body: "new value", contentType: "new content-type", revision: "remote" }
850+
};
851+
});
852+
853+
it("emits a 'change' event", function(done) {
854+
this.rs.local.emitChange = function(changeEvent) {
855+
expect(changeEvent).to.deep.equal({
856+
origin: "remote",
857+
path: "foo",
858+
newValue: "new value",
859+
oldValue: undefined,
860+
newContentType: "new content-type",
861+
oldContentType: undefined
862+
});
863+
done();
864+
};
865+
866+
this.rs.sync.autoMerge(this.node);
867+
});
868+
869+
it("merges the node items", function() {
870+
expect(this.rs.sync.autoMerge(this.node)).to.deep.equal({
871+
path: "foo",
872+
common: { body: "new value", contentType: "new content-type", revision: "remote" }
873+
});
874+
});
875+
876+
describe("with zero-length body", function() {
877+
beforeEach(function() {
878+
this.node = {
879+
path: "foo",
880+
common: {},
881+
remote: { body: "", contentType: "new content-type", revision: "remote" }
882+
};
883+
});
884+
885+
it("emits a 'change' event", function(done) {
886+
this.rs.local.emitChange = function(changeEvent) {
887+
expect(changeEvent).to.deep.equal({
888+
origin: "remote",
889+
path: "foo",
890+
newValue: "",
891+
oldValue: undefined,
892+
newContentType: "new content-type",
893+
oldContentType: undefined
894+
});
895+
done();
896+
};
897+
898+
this.rs.sync.autoMerge(this.node);
899+
});
900+
901+
it("merges the node items", function() {
902+
expect(this.rs.sync.autoMerge(this.node)).to.deep.equal({
903+
path: "foo",
904+
common: { body: "", contentType: "new content-type", revision: "remote" }
905+
});
906+
});
907+
});
908+
});
909+
910+
describe("updated node", function() {
845911
beforeEach(function() {
846912
this.node = {
847913
path: "foo",
@@ -872,9 +938,42 @@ describe("Sync", function() {
872938
common: { body: "new value", contentType: "new content-type", revision: "remote" }
873939
});
874940
});
941+
942+
describe("with zero-length body", function() {
943+
beforeEach(function() {
944+
this.node = {
945+
path: "foo",
946+
common: { body: "old value", contentType: "old content-type", revision: "common" },
947+
remote: { body: "", contentType: "new content-type", revision: "remote" }
948+
};
949+
});
950+
951+
it("emits a 'change' event", function(done) {
952+
this.rs.local.emitChange = function(changeEvent) {
953+
expect(changeEvent).to.deep.equal({
954+
origin: "remote",
955+
path: "foo",
956+
newValue: "",
957+
oldValue: "old value",
958+
newContentType: "new content-type",
959+
oldContentType: "old content-type"
960+
});
961+
done();
962+
};
963+
964+
this.rs.sync.autoMerge(this.node);
965+
});
966+
967+
it("merges the node items", function() {
968+
expect(this.rs.sync.autoMerge(this.node)).to.deep.equal({
969+
path: "foo",
970+
common: { body: "", contentType: "new content-type", revision: "remote" }
971+
});
972+
});
973+
});
875974
});
876975

877-
describe("when node was deleted", function() {
976+
describe("deleted node", function() {
878977
describe("with node cached before", function() {
879978
beforeEach(function() {
880979
this.node = {

0 commit comments

Comments
 (0)