2014-03-10 12:58:26 -04:00
|
|
|
sinon = require('sinon')
|
|
|
|
chai = require('chai')
|
|
|
|
should = chai.should()
|
|
|
|
expect = chai.expect
|
|
|
|
modulePath = "../../../../app/js/RestoreManager.js"
|
|
|
|
SandboxedModule = require('sandboxed-module')
|
|
|
|
|
|
|
|
describe "RestoreManager", ->
|
|
|
|
beforeEach ->
|
|
|
|
@RestoreManager = SandboxedModule.require modulePath, requires:
|
|
|
|
"logger-sharelatex": @logger = { log: sinon.stub(), error: sinon.stub() }
|
|
|
|
"./DocumentUpdaterManager": @DocumentUpdaterManager = {}
|
|
|
|
"./DiffManager": @DiffManager = {}
|
|
|
|
@callback = sinon.stub()
|
|
|
|
@project_id = "mock-project-id"
|
|
|
|
@doc_id = "mock-doc-id"
|
2014-03-11 09:01:07 -04:00
|
|
|
@user_id = "mock-user-id"
|
2014-03-10 12:58:26 -04:00
|
|
|
@version = 42
|
|
|
|
|
|
|
|
describe "restoreToBeforeVersion", ->
|
|
|
|
beforeEach ->
|
|
|
|
@content = "mock content"
|
2014-03-11 09:01:07 -04:00
|
|
|
@DocumentUpdaterManager.setDocument = sinon.stub().callsArg(4)
|
2014-03-10 12:58:26 -04:00
|
|
|
@DiffManager.getDocumentBeforeVersion = sinon.stub().callsArgWith(3, null, @content)
|
2014-03-11 09:01:07 -04:00
|
|
|
@RestoreManager.restoreToBeforeVersion @project_id, @doc_id, @version, @user_id, @callback
|
2014-03-10 12:58:26 -04:00
|
|
|
|
|
|
|
it "should get the content before the requested version", ->
|
|
|
|
@DiffManager.getDocumentBeforeVersion
|
|
|
|
.calledWith(@project_id, @doc_id, @version)
|
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should set the document in the document updater", ->
|
|
|
|
@DocumentUpdaterManager.setDocument
|
2014-03-11 09:01:07 -04:00
|
|
|
.calledWith(@project_id, @doc_id, @content, @user_id)
|
2014-03-10 12:58:26 -04:00
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should call the callback", ->
|
|
|
|
@callback.called.should.equal true
|
|
|
|
|