From 5e730b33b208da5b5893809e1e3b54da93682c96 Mon Sep 17 00:00:00 2001 From: James Allen Date: Fri, 16 Dec 2016 16:44:08 +0000 Subject: [PATCH] Support new comment op format --- .../docstore/app/coffee/RangeManager.coffee | 4 +-- .../test/unit/coffee/RangeManagerTests.coffee | 30 +++++++------------ 2 files changed, 12 insertions(+), 22 deletions(-) diff --git a/services/docstore/app/coffee/RangeManager.coffee b/services/docstore/app/coffee/RangeManager.coffee index 4022d55d04..b46fe50b26 100644 --- a/services/docstore/app/coffee/RangeManager.coffee +++ b/services/docstore/app/coffee/RangeManager.coffee @@ -26,8 +26,8 @@ module.exports = RangeManager = change.metadata.user_id = @_safeObjectId(change.metadata.user_id) for comment in ranges.comments or [] comment.id = @_safeObjectId(comment.id) - if comment.metadata?.ts? - comment.metadata.ts = new Date(comment.metadata.ts) + if comment.op?.t? + comment.op.t = @_safeObjectId(comment.op.t) return ranges _safeObjectId: (data) -> diff --git a/services/docstore/test/unit/coffee/RangeManagerTests.coffee b/services/docstore/test/unit/coffee/RangeManagerTests.coffee index bf8b01e7d7..0fe3983982 100644 --- a/services/docstore/test/unit/coffee/RangeManagerTests.coffee +++ b/services/docstore/test/unit/coffee/RangeManagerTests.coffee @@ -17,6 +17,7 @@ describe "RangeManager", -> change_id = ObjectId().toString() comment_id = ObjectId().toString() user_id = ObjectId().toString() + thread_id = ObjectId().toString() ts = new Date().toJSON() @RangeManager.jsonRangesToMongo({ changes: [{ @@ -28,10 +29,7 @@ describe "RangeManager", -> }] comments: [{ id: comment_id - offset: 42 - length: 5 - metadata: - ts: ts + op: { c: "foo", p: 3, t: thread_id } }] }).should.deep.equal { changes: [{ @@ -43,10 +41,7 @@ describe "RangeManager", -> }] comments: [{ id: ObjectId(comment_id) - offset: 42 - length: 5 - metadata: - ts: new Date(ts) + op: { c: "foo", p: 3, t: ObjectId(thread_id) } }] } @@ -78,6 +73,7 @@ describe "RangeManager", -> change_id = ObjectId().toString() comment_id = ObjectId().toString() user_id = ObjectId().toString() + thread_id = ObjectId().toString() ts = new Date().toJSON() ranges1 = { changes: [{ @@ -89,10 +85,7 @@ describe "RangeManager", -> }] comments: [{ id: comment_id - offset: 42 - length: 5 - metadata: - ts: ts + op: { c: "foo", p: 3, t: thread_id } }] } ranges1_copy = JSON.parse(JSON.stringify(ranges1)) # jsonRangesToMongo modifies in place @@ -111,10 +104,7 @@ describe "RangeManager", -> }] comments: [{ id: ObjectId() - offset: 42 - length: 5 - metadata: - ts: new Date() + op: { c: "foo", p: 3, t: ObjectId() } }] } @ranges_copy = @RangeManager.jsonRangesToMongo(JSON.parse(JSON.stringify(@ranges))) @@ -153,10 +143,10 @@ describe "RangeManager", -> @ranges_copy.comments[0].id = ObjectId() @RangeManager.shouldUpdateRanges(@ranges, @ranges_copy).should.equal true - it "should return true when the comment ts changes", -> - @ranges_copy.comments[0].metadata.ts = new Date(Date.now() + 1000) + it "should return true when the comment offset changes", -> + @ranges_copy.comments[0].op.p = 17 @RangeManager.shouldUpdateRanges(@ranges, @ranges_copy).should.equal true - it "should return true when the comment offset changes", -> - @ranges_copy.comments[0].offset = 17 + it "should return true when the comment content changes", -> + @ranges_copy.comments[0].op.c = "bar" @RangeManager.shouldUpdateRanges(@ranges, @ranges_copy).should.equal true \ No newline at end of file