From 4504bbae52216455eb9b4c9ce1cf4433246283b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Sat, 26 May 2018 13:50:31 -0400 Subject: [PATCH] 2 diff test --- src/posts/diffs.js | 4 +++- test/posts.js | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/posts/diffs.js b/src/posts/diffs.js index 6efaabcfb9..deec210619 100644 --- a/src/posts/diffs.js +++ b/src/posts/diffs.js @@ -23,7 +23,9 @@ Diffs.exists = function (pid, callback) { Diffs.get = function (pid, since, callback) { async.waterfall([ - async.apply(db.getListRange.bind(db), 'post:' + pid + ':diffs', 0, -1), + function (next) { + Diffs.list(pid, next); + }, function (timestamps, next) { // Pass those made after `since`, and create keys const keys = timestamps.filter(function (timestamp) { diff --git a/test/posts.js b/test/posts.js index f6b2c28261..6401d35bc0 100644 --- a/test/posts.js +++ b/test/posts.js @@ -443,6 +443,24 @@ describe('Post\'s', function () { done(); }); }); + + it('should return diffs', function (done) { + posts.diffs.get(replyPid, 0, function (err, data) { + assert.ifError(err); + assert(Array.isArray(data)); + assert(data[0].pid, replyPid); + assert(data[0].patch); + done(); + }); + }); + + it('should load diffs and reconstruct post', function (done) { + posts.diffs.load(replyPid, 0, voterUid, function (err, data) { + assert.ifError(err); + assert.equal(data.content, 'A reply to edit\n'); + done(); + }); + }); }); describe('move', function () {