|
|
@@ -7,6 +7,7 @@ rclient_du = require("redis-sharelatex").createClient(Settings.redis.documentupd
|
|
|
Keys = Settings.redis.documentupdater.key_schema
|
|
|
|
|
|
MockTrackChangesApi = require "./helpers/MockTrackChangesApi"
|
|
|
+MockProjectHistoryApi = require "./helpers/MockProjectHistoryApi"
|
|
|
MockWebApi = require "./helpers/MockWebApi"
|
|
|
DocUpdaterClient = require "./helpers/DocUpdaterClient"
|
|
|
|
|
|
@@ -25,14 +26,16 @@ describe "Setting a document", ->
|
|
|
@newLines = ["these", "are", "the", "new", "lines"]
|
|
|
@source = "dropbox"
|
|
|
@user_id = "user-id-123"
|
|
|
-
|
|
|
+
|
|
|
sinon.spy MockTrackChangesApi, "flushDoc"
|
|
|
+ sinon.spy MockProjectHistoryApi, "flushProject"
|
|
|
sinon.spy MockWebApi, "setDocument"
|
|
|
-
|
|
|
+
|
|
|
after ->
|
|
|
- MockWebApi.setDocument.restore()
|
|
|
MockTrackChangesApi.flushDoc.restore()
|
|
|
-
|
|
|
+ MockProjectHistoryApi.flushProject.restore()
|
|
|
+ MockWebApi.setDocument.restore()
|
|
|
+
|
|
|
describe "when the updated doc exists in the doc updater", ->
|
|
|
before (done) ->
|
|
|
[@project_id, @doc_id] = [DocUpdaterClient.randomId(), DocUpdaterClient.randomId()]
|
|
|
@@ -64,13 +67,13 @@ describe "Setting a document", ->
|
|
|
DocUpdaterClient.getDoc @project_id, @doc_id, (error, res, doc) =>
|
|
|
doc.version.should.equal @version + 2
|
|
|
done()
|
|
|
-
|
|
|
+
|
|
|
it "should leave the document in redis", (done) ->
|
|
|
rclient_du.get Keys.docLines({doc_id: @doc_id}), (error, lines) =>
|
|
|
throw error if error?
|
|
|
expect(JSON.parse(lines)).to.deep.equal @newLines
|
|
|
done()
|
|
|
-
|
|
|
+
|
|
|
describe "when the updated doc does not exist in the doc updater", ->
|
|
|
before (done) ->
|
|
|
[@project_id, @doc_id] = [DocUpdaterClient.randomId(), DocUpdaterClient.randomId()]
|
|
|
@@ -78,7 +81,7 @@ describe "Setting a document", ->
|
|
|
DocUpdaterClient.setDocLines @project_id, @doc_id, @newLines, @source, @user_id, false, (error, res, body) =>
|
|
|
@statusCode = res.statusCode
|
|
|
setTimeout done, 200
|
|
|
-
|
|
|
+
|
|
|
it "should return a 204 status code", ->
|
|
|
@statusCode.should.equal 204
|
|
|
|
|
|
@@ -86,16 +89,19 @@ describe "Setting a document", ->
|
|
|
MockWebApi.setDocument
|
|
|
.calledWith(@project_id, @doc_id, @newLines)
|
|
|
.should.equal true
|
|
|
-
|
|
|
+
|
|
|
it "should flush track changes", ->
|
|
|
MockTrackChangesApi.flushDoc.calledWith(@doc_id).should.equal true
|
|
|
-
|
|
|
+
|
|
|
+ it "should flush project history", ->
|
|
|
+ MockProjectHistoryApi.flushProject.calledWith(@project_id).should.equal true
|
|
|
+
|
|
|
it "should remove the document from redis", (done) ->
|
|
|
rclient_du.get Keys.docLines({doc_id: @doc_id}), (error, lines) =>
|
|
|
throw error if error?
|
|
|
expect(lines).to.not.exist
|
|
|
done()
|
|
|
-
|
|
|
+
|
|
|
describe "with track changes", ->
|
|
|
before ->
|
|
|
@lines = ["one", "one and a half", "two", "three"]
|
|
|
@@ -123,14 +129,14 @@ describe "Setting a document", ->
|
|
|
DocUpdaterClient.setDocLines @project_id, @doc_id, @lines, @source, @user_id, true, (error, res, body) =>
|
|
|
@statusCode = res.statusCode
|
|
|
setTimeout done, 200
|
|
|
-
|
|
|
+
|
|
|
it "should undo the tracked changes", (done) ->
|
|
|
DocUpdaterClient.getDoc @project_id, @doc_id, (error, res, data) =>
|
|
|
throw error if error?
|
|
|
ranges = data.ranges
|
|
|
expect(ranges.changes).to.be.undefined
|
|
|
done()
|
|
|
-
|
|
|
+
|
|
|
describe "without the undo flag", ->
|
|
|
before (done) ->
|
|
|
[@project_id, @doc_id] = [DocUpdaterClient.randomId(), DocUpdaterClient.randomId()]
|
|
|
@@ -143,7 +149,7 @@ describe "Setting a document", ->
|
|
|
DocUpdaterClient.setDocLines @project_id, @doc_id, @lines, @source, @user_id, false, (error, res, body) =>
|
|
|
@statusCode = res.statusCode
|
|
|
setTimeout done, 200
|
|
|
-
|
|
|
+
|
|
|
it "should not undo the tracked changes", (done) ->
|
|
|
DocUpdaterClient.getDoc @project_id, @doc_id, (error, res, data) =>
|
|
|
throw error if error?
|
|
|
@@ -151,4 +157,4 @@ describe "Setting a document", ->
|
|
|
expect(ranges.changes.length).to.equal 1
|
|
|
done()
|
|
|
|
|
|
-
|
|
|
+
|