2014-02-12 05:40:42 -05:00
|
|
|
sinon = require "sinon"
|
|
|
|
chai = require("chai")
|
|
|
|
chai.should()
|
|
|
|
async = require "async"
|
|
|
|
|
2016-01-20 10:05:31 -05:00
|
|
|
MockTrackChangesApi = require "./helpers/MockTrackChangesApi"
|
2017-10-05 10:14:35 -04:00
|
|
|
MockProjectHistoryApi = require "./helpers/MockProjectHistoryApi"
|
2014-02-12 05:40:42 -05:00
|
|
|
MockWebApi = require "./helpers/MockWebApi"
|
|
|
|
DocUpdaterClient = require "./helpers/DocUpdaterClient"
|
2018-02-15 11:28:40 -05:00
|
|
|
DocUpdaterApp = require "./helpers/DocUpdaterApp"
|
2014-02-12 05:40:42 -05:00
|
|
|
|
|
|
|
describe "Deleting a project", ->
|
2018-02-15 11:28:40 -05:00
|
|
|
before (done) ->
|
2014-02-12 05:40:42 -05:00
|
|
|
@project_id = DocUpdaterClient.randomId()
|
|
|
|
@docs = [{
|
|
|
|
id: doc_id0 = DocUpdaterClient.randomId()
|
|
|
|
lines: ["one", "two", "three"]
|
|
|
|
update:
|
|
|
|
doc: doc_id0
|
|
|
|
op: [{
|
|
|
|
i: "one and a half\n"
|
|
|
|
p: 4
|
|
|
|
}]
|
|
|
|
v: 0
|
|
|
|
updatedLines: ["one", "one and a half", "two", "three"]
|
|
|
|
}, {
|
|
|
|
id: doc_id1 = DocUpdaterClient.randomId()
|
|
|
|
lines: ["four", "five", "six"]
|
|
|
|
update:
|
|
|
|
doc: doc_id1
|
|
|
|
op: [{
|
|
|
|
i: "four and a half\n"
|
|
|
|
p: 5
|
|
|
|
}]
|
|
|
|
v: 0
|
|
|
|
updatedLines: ["four", "four and a half", "five", "six"]
|
|
|
|
}]
|
|
|
|
for doc in @docs
|
|
|
|
MockWebApi.insertDoc @project_id, doc.id, {
|
|
|
|
lines: doc.lines
|
2014-02-10 10:17:08 -05:00
|
|
|
version: doc.update.v
|
2014-02-12 05:40:42 -05:00
|
|
|
}
|
2017-10-05 10:14:35 -04:00
|
|
|
|
2016-01-20 10:05:31 -05:00
|
|
|
sinon.spy MockTrackChangesApi, "flushDoc"
|
2017-10-05 10:14:35 -04:00
|
|
|
sinon.spy MockProjectHistoryApi, "flushProject"
|
2018-02-15 11:28:40 -05:00
|
|
|
DocUpdaterApp.ensureRunning(done)
|
2017-10-05 10:14:35 -04:00
|
|
|
|
2016-01-20 10:05:31 -05:00
|
|
|
after ->
|
|
|
|
MockTrackChangesApi.flushDoc.restore()
|
2017-10-05 10:14:35 -04:00
|
|
|
MockProjectHistoryApi.flushProject.restore()
|
2014-02-12 05:40:42 -05:00
|
|
|
|
|
|
|
describe "with documents which have been updated", ->
|
|
|
|
before (done) ->
|
2016-11-29 12:06:23 -05:00
|
|
|
sinon.spy MockWebApi, "setDocument"
|
2014-02-12 05:40:42 -05:00
|
|
|
async.series @docs.map((doc) =>
|
|
|
|
(callback) =>
|
|
|
|
DocUpdaterClient.preloadDoc @project_id, doc.id, (error) =>
|
|
|
|
return callback(error) if error?
|
|
|
|
DocUpdaterClient.sendUpdate @project_id, doc.id, doc.update, (error) =>
|
|
|
|
callback(error)
|
|
|
|
), (error) =>
|
|
|
|
throw error if error?
|
|
|
|
setTimeout () =>
|
|
|
|
DocUpdaterClient.deleteProject @project_id, (error, res, body) =>
|
|
|
|
@statusCode = res.statusCode
|
|
|
|
done()
|
|
|
|
, 200
|
|
|
|
|
|
|
|
after ->
|
2016-11-29 12:06:23 -05:00
|
|
|
MockWebApi.setDocument.restore()
|
2014-02-12 05:40:42 -05:00
|
|
|
|
|
|
|
it "should return a 204 status code", ->
|
|
|
|
@statusCode.should.equal 204
|
|
|
|
|
|
|
|
it "should send each document to the web api", ->
|
|
|
|
for doc in @docs
|
2016-11-29 12:06:23 -05:00
|
|
|
MockWebApi.setDocument
|
2014-02-12 05:40:42 -05:00
|
|
|
.calledWith(@project_id, doc.id, doc.updatedLines)
|
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should need to reload the docs if read again", (done) ->
|
|
|
|
sinon.spy MockWebApi, "getDocument"
|
|
|
|
async.series @docs.map((doc) =>
|
|
|
|
(callback) =>
|
|
|
|
MockWebApi.getDocument.calledWith(@project_id, doc.id).should.equal false
|
|
|
|
DocUpdaterClient.getDoc @project_id, doc.id, (error, res, returnedDoc) =>
|
|
|
|
MockWebApi.getDocument.calledWith(@project_id, doc.id).should.equal true
|
|
|
|
callback()
|
|
|
|
), () ->
|
|
|
|
MockWebApi.getDocument.restore()
|
|
|
|
done()
|
2017-10-05 10:14:35 -04:00
|
|
|
|
2016-01-20 10:05:31 -05:00
|
|
|
it "should flush each doc in track changes", ->
|
|
|
|
for doc in @docs
|
|
|
|
MockTrackChangesApi.flushDoc.calledWith(doc.id).should.equal true
|
2014-02-12 05:40:42 -05:00
|
|
|
|
2017-10-05 10:14:35 -04:00
|
|
|
it "should flush each doc in project history", ->
|
|
|
|
MockProjectHistoryApi.flushProject.calledWith(@project_id).should.equal true
|