|
|
@@ -53,6 +53,11 @@ describe "Setting a document", ->
|
|
|
, 200
|
|
|
return null
|
|
|
|
|
|
+ after ->
|
|
|
+ MockTrackChangesApi.flushDoc.reset()
|
|
|
+ MockProjectHistoryApi.flushProject.reset()
|
|
|
+ MockWebApi.setDocument.reset()
|
|
|
+
|
|
|
it "should return a 204 status code", ->
|
|
|
@statusCode.should.equal 204
|
|
|
|
|
|
@@ -89,6 +94,11 @@ describe "Setting a document", ->
|
|
|
setTimeout done, 200
|
|
|
return null
|
|
|
|
|
|
+ after ->
|
|
|
+ MockTrackChangesApi.flushDoc.reset()
|
|
|
+ MockProjectHistoryApi.flushProject.reset()
|
|
|
+ MockWebApi.setDocument.reset()
|
|
|
+
|
|
|
it "should return a 204 status code", ->
|
|
|
@statusCode.should.equal 204
|
|
|
|
|
|
@@ -110,6 +120,64 @@ describe "Setting a document", ->
|
|
|
done()
|
|
|
return null
|
|
|
|
|
|
+ describe "when the updated doc is too large for the body parser", ->
|
|
|
+ before (done) ->
|
|
|
+ [@project_id, @doc_id] = [DocUpdaterClient.randomId(), DocUpdaterClient.randomId()]
|
|
|
+ MockWebApi.insertDoc @project_id, @doc_id, {lines: @lines, version: @version}
|
|
|
+ @newLines = []
|
|
|
+ while JSON.stringify(@newLines).length < Settings.max_doc_length + 64 * 1024
|
|
|
+ @newLines.push("(a long line of text)".repeat(10000))
|
|
|
+ console.log("newlines size",JSON.stringify(@newLines).length)
|
|
|
+ DocUpdaterClient.setDocLines @project_id, @doc_id, @newLines, @source, @user_id, false, (error, res, body) =>
|
|
|
+ @statusCode = res.statusCode
|
|
|
+ setTimeout done, 200
|
|
|
+ return null
|
|
|
+
|
|
|
+ after ->
|
|
|
+ MockTrackChangesApi.flushDoc.reset()
|
|
|
+ MockProjectHistoryApi.flushProject.reset()
|
|
|
+ MockWebApi.setDocument.reset()
|
|
|
+
|
|
|
+ it "should return a 413 status code", ->
|
|
|
+ @statusCode.should.equal 413
|
|
|
+
|
|
|
+ it "should not send the updated doc lines to the web api", ->
|
|
|
+ MockWebApi.setDocument.called.should.equal false
|
|
|
+
|
|
|
+ it "should not flush track changes", ->
|
|
|
+ MockTrackChangesApi.flushDoc.called.should.equal false
|
|
|
+
|
|
|
+ it "should not flush project history", ->
|
|
|
+ MockProjectHistoryApi.flushProject.called.should.equal false
|
|
|
+
|
|
|
+ describe "when the updated doc is large but under the bodyParser and HTTPController size limit", ->
|
|
|
+ before (done) ->
|
|
|
+ [@project_id, @doc_id] = [DocUpdaterClient.randomId(), DocUpdaterClient.randomId()]
|
|
|
+ MockWebApi.insertDoc @project_id, @doc_id, {lines: @lines, version: @version}
|
|
|
+
|
|
|
+ @newLines = []
|
|
|
+ while JSON.stringify(@newLines).length < 2 * 1024 * 1024 # limit in HTTPController
|
|
|
+ @newLines.push("(a long line of text)".repeat(10000))
|
|
|
+ @newLines.pop() # remove the line which took it over the limit
|
|
|
+ console.log("newlines size",JSON.stringify(@newLines).length)
|
|
|
+ DocUpdaterClient.setDocLines @project_id, @doc_id, @newLines, @source, @user_id, false, (error, res, body) =>
|
|
|
+ @statusCode = res.statusCode
|
|
|
+ setTimeout done, 200
|
|
|
+ return null
|
|
|
+
|
|
|
+ after ->
|
|
|
+ MockTrackChangesApi.flushDoc.reset()
|
|
|
+ MockProjectHistoryApi.flushProject.reset()
|
|
|
+ MockWebApi.setDocument.reset()
|
|
|
+
|
|
|
+ it "should return a 204 status code", ->
|
|
|
+ @statusCode.should.equal 204
|
|
|
+
|
|
|
+ it "should send the updated doc lines to the web api", ->
|
|
|
+ MockWebApi.setDocument
|
|
|
+ .calledWith(@project_id, @doc_id, @newLines)
|
|
|
+ .should.equal true
|
|
|
+
|
|
|
describe "with track changes", ->
|
|
|
before ->
|
|
|
@lines = ["one", "one and a half", "two", "three"]
|
|
|
@@ -139,6 +207,11 @@ describe "Setting a document", ->
|
|
|
setTimeout done, 200
|
|
|
return null
|
|
|
|
|
|
+ after ->
|
|
|
+ MockTrackChangesApi.flushDoc.reset()
|
|
|
+ MockProjectHistoryApi.flushProject.reset()
|
|
|
+ MockWebApi.setDocument.reset()
|
|
|
+
|
|
|
it "should undo the tracked changes", (done) ->
|
|
|
DocUpdaterClient.getDoc @project_id, @doc_id, (error, res, data) =>
|
|
|
throw error if error?
|
|
|
@@ -161,6 +234,11 @@ describe "Setting a document", ->
|
|
|
setTimeout done, 200
|
|
|
return null
|
|
|
|
|
|
+ after ->
|
|
|
+ MockTrackChangesApi.flushDoc.reset()
|
|
|
+ MockProjectHistoryApi.flushProject.reset()
|
|
|
+ MockWebApi.setDocument.reset()
|
|
|
+
|
|
|
it "should not undo the tracked changes", (done) ->
|
|
|
DocUpdaterClient.getDoc @project_id, @doc_id, (error, res, data) =>
|
|
|
throw error if error?
|