2014-01-27 13:09:37 -05:00
|
|
|
sinon = require('sinon')
|
|
|
|
chai = require('chai')
|
|
|
|
should = chai.should()
|
|
|
|
expect = chai.expect
|
|
|
|
modulePath = "../../../../app/js/HttpController.js"
|
|
|
|
SandboxedModule = require('sandboxed-module')
|
|
|
|
|
|
|
|
describe "HttpController", ->
|
|
|
|
beforeEach ->
|
|
|
|
@HttpController = SandboxedModule.require modulePath, requires:
|
|
|
|
"logger-sharelatex": { log: sinon.stub() }
|
2014-03-05 10:59:40 -05:00
|
|
|
"./UpdatesManager": @UpdatesManager = {}
|
2014-03-04 10:27:03 -05:00
|
|
|
"./DiffManager": @DiffManager = {}
|
2014-03-10 12:58:26 -04:00
|
|
|
"./RestoreManager": @RestoreManager = {}
|
2015-06-05 05:59:09 -04:00
|
|
|
"./PackManager": @PackManager = {}
|
2015-08-31 17:13:18 -04:00
|
|
|
"./DocArchiveManager": @DocArchiveManager = {}
|
2016-01-27 11:04:55 -05:00
|
|
|
"./HealthChecker": @HealthChecker = {}
|
2014-01-27 13:09:37 -05:00
|
|
|
@doc_id = "doc-id-123"
|
2014-03-04 10:27:03 -05:00
|
|
|
@project_id = "project-id-123"
|
2014-01-27 13:09:37 -05:00
|
|
|
@next = sinon.stub()
|
2014-03-11 09:01:07 -04:00
|
|
|
@user_id = "mock-user-123"
|
2014-03-11 13:39:40 -04:00
|
|
|
@now = Date.now()
|
2014-01-27 13:09:37 -05:00
|
|
|
|
2014-03-21 11:57:17 -04:00
|
|
|
describe "flushDoc", ->
|
2014-01-27 13:09:37 -05:00
|
|
|
beforeEach ->
|
|
|
|
@req =
|
|
|
|
params:
|
|
|
|
doc_id: @doc_id
|
2014-03-19 12:40:55 -04:00
|
|
|
project_id: @project_id
|
2014-01-27 13:09:37 -05:00
|
|
|
@res =
|
|
|
|
send: sinon.stub()
|
2014-03-19 12:40:55 -04:00
|
|
|
@UpdatesManager.processUncompressedUpdatesWithLock = sinon.stub().callsArg(2)
|
2014-03-21 11:57:17 -04:00
|
|
|
@HttpController.flushDoc @req, @res, @next
|
2014-01-27 13:09:37 -05:00
|
|
|
|
2014-02-26 06:34:56 -05:00
|
|
|
it "should process the updates", ->
|
2014-03-05 10:59:40 -05:00
|
|
|
@UpdatesManager.processUncompressedUpdatesWithLock
|
2014-03-19 12:40:55 -04:00
|
|
|
.calledWith(@project_id, @doc_id)
|
2014-01-27 13:09:37 -05:00
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should return a success code", ->
|
2014-03-04 10:27:03 -05:00
|
|
|
@res.send.calledWith(204).should.equal true
|
|
|
|
|
2014-03-21 11:57:17 -04:00
|
|
|
describe "flushProject", ->
|
|
|
|
beforeEach ->
|
|
|
|
@req =
|
|
|
|
params:
|
|
|
|
project_id: @project_id
|
|
|
|
@res =
|
|
|
|
send: sinon.stub()
|
|
|
|
@UpdatesManager.processUncompressedUpdatesForProject = sinon.stub().callsArg(1)
|
|
|
|
@HttpController.flushProject @req, @res, @next
|
|
|
|
|
|
|
|
it "should process the updates", ->
|
|
|
|
@UpdatesManager.processUncompressedUpdatesForProject
|
|
|
|
.calledWith(@project_id)
|
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should return a success code", ->
|
|
|
|
@res.send.calledWith(204).should.equal true
|
|
|
|
|
|
|
|
|
2014-03-04 10:27:03 -05:00
|
|
|
describe "getDiff", ->
|
|
|
|
beforeEach ->
|
2014-03-10 12:58:26 -04:00
|
|
|
@from = 42
|
|
|
|
@to = 45
|
2014-03-04 10:27:03 -05:00
|
|
|
@req =
|
|
|
|
params:
|
|
|
|
doc_id: @doc_id
|
|
|
|
project_id: @project_id
|
|
|
|
query:
|
|
|
|
from: @from.toString()
|
|
|
|
to: @to.toString()
|
|
|
|
@res =
|
|
|
|
send: sinon.stub()
|
|
|
|
@diff = [ u: "mock-diff" ]
|
|
|
|
@DiffManager.getDiff = sinon.stub().callsArgWith(4, null, @diff)
|
|
|
|
@HttpController.getDiff @req, @res, @next
|
|
|
|
|
|
|
|
it "should get the diff", ->
|
|
|
|
@DiffManager.getDiff
|
|
|
|
.calledWith(@project_id, @doc_id, parseInt(@from, 10), parseInt(@to, 10))
|
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should return the diff", ->
|
|
|
|
@res.send.calledWith(JSON.stringify(diff: @diff)).should.equal true
|
2014-03-05 10:59:40 -05:00
|
|
|
|
|
|
|
describe "getUpdates", ->
|
|
|
|
beforeEach ->
|
2014-03-20 08:10:04 -04:00
|
|
|
@before = Date.now()
|
|
|
|
@nextBeforeTimestamp = @before - 100
|
|
|
|
@min_count = 10
|
2014-03-05 10:59:40 -05:00
|
|
|
@req =
|
|
|
|
params:
|
|
|
|
project_id: @project_id
|
|
|
|
query:
|
2014-03-20 08:10:04 -04:00
|
|
|
before: @before.toString()
|
|
|
|
min_count: @min_count.toString()
|
2014-03-05 10:59:40 -05:00
|
|
|
@res =
|
|
|
|
send: sinon.stub()
|
2014-03-18 07:41:48 -04:00
|
|
|
@updates = ["mock-summarized-updates"]
|
2014-03-20 08:10:04 -04:00
|
|
|
@UpdatesManager.getSummarizedProjectUpdates = sinon.stub().callsArgWith(2, null, @updates, @nextBeforeTimestamp)
|
2014-03-05 10:59:40 -05:00
|
|
|
@HttpController.getUpdates @req, @res, @next
|
|
|
|
|
|
|
|
it "should get the updates", ->
|
2014-03-20 08:10:04 -04:00
|
|
|
@UpdatesManager.getSummarizedProjectUpdates
|
|
|
|
.calledWith(@project_id, before: @before, min_count: @min_count)
|
2014-03-05 10:59:40 -05:00
|
|
|
.should.equal true
|
|
|
|
|
2014-03-06 13:04:00 -05:00
|
|
|
it "should return the formatted updates", ->
|
2014-03-20 08:10:04 -04:00
|
|
|
@res.send.calledWith(JSON.stringify(updates: @updates, nextBeforeTimestamp: @nextBeforeTimestamp)).should.equal true
|
2014-03-10 12:58:26 -04:00
|
|
|
|
|
|
|
describe "RestoreManager", ->
|
|
|
|
beforeEach ->
|
|
|
|
@version = "42"
|
|
|
|
@req =
|
|
|
|
params:
|
|
|
|
doc_id: @doc_id
|
|
|
|
project_id: @project_id
|
|
|
|
version: @version
|
2014-03-11 09:01:07 -04:00
|
|
|
headers:
|
|
|
|
"x-user-id": @user_id
|
2014-03-10 12:58:26 -04:00
|
|
|
@res =
|
|
|
|
send: sinon.stub()
|
|
|
|
|
2014-03-11 09:01:07 -04:00
|
|
|
@RestoreManager.restoreToBeforeVersion = sinon.stub().callsArg(4)
|
2014-03-10 12:58:26 -04:00
|
|
|
@HttpController.restore @req, @res, @next
|
|
|
|
|
|
|
|
it "should restore the document", ->
|
|
|
|
@RestoreManager.restoreToBeforeVersion
|
2014-03-11 09:01:07 -04:00
|
|
|
.calledWith(@project_id, @doc_id, parseInt(@version, 10), @user_id)
|
2014-03-10 12:58:26 -04:00
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should return a success code", ->
|
|
|
|
@res.send.calledWith(204).should.equal true
|
2015-08-31 17:13:18 -04:00
|
|
|
|