2014-02-12 05:40:42 -05:00
|
|
|
sinon = require('sinon')
|
|
|
|
chai = require('chai')
|
|
|
|
should = chai.should()
|
|
|
|
modulePath = "../../../../app/js/PersistenceManager.js"
|
|
|
|
SandboxedModule = require('sandboxed-module')
|
|
|
|
|
|
|
|
describe "PersistenceManager.setDoc", ->
|
|
|
|
beforeEach ->
|
|
|
|
@PersistenceManager = SandboxedModule.require modulePath, requires:
|
|
|
|
"request": @request = sinon.stub()
|
|
|
|
"settings-sharelatex": @Settings = {}
|
|
|
|
"./Metrics": @Metrics =
|
|
|
|
Timer: class Timer
|
|
|
|
done: sinon.stub()
|
2014-05-14 11:04:25 -04:00
|
|
|
"logger-sharelatex": @logger = {warn: sinon.stub()}
|
2014-02-12 05:40:42 -05:00
|
|
|
|
2014-05-14 11:04:25 -04:00
|
|
|
@project_id = "mock-project-id"
|
|
|
|
@doc_id = "mock-doc-id"
|
|
|
|
@callback = sinon.stub()
|
|
|
|
@lines = ["mock", "doc", "lines"]
|
2014-02-12 05:40:42 -05:00
|
|
|
|
2014-05-15 06:13:16 -04:00
|
|
|
@PersistenceManager.setDocInWeb = sinon.stub().callsArg(3)
|
2014-05-14 11:04:25 -04:00
|
|
|
@PersistenceManager.setDocVersionInMongo = sinon.stub().callsArg(2)
|
2014-02-12 05:40:42 -05:00
|
|
|
|
2014-05-14 11:04:25 -04:00
|
|
|
@PersistenceManager.setDoc @project_id, @doc_id, @lines, @version, @callback
|
2014-02-12 05:40:42 -05:00
|
|
|
|
2014-05-14 11:04:25 -04:00
|
|
|
it "should set the doc in the web api", ->
|
|
|
|
@PersistenceManager.setDocInWeb
|
2014-05-15 06:13:16 -04:00
|
|
|
.calledWith(@project_id, @doc_id, @lines)
|
2014-05-14 11:04:25 -04:00
|
|
|
.should.equal true
|
2014-02-12 05:40:42 -05:00
|
|
|
|
2014-05-14 11:04:25 -04:00
|
|
|
it "should set the doc version in mongo", ->
|
|
|
|
@PersistenceManager.setDocVersionInMongo
|
|
|
|
.calledWith(@doc_id, @version)
|
|
|
|
.should.equal true
|
2014-02-12 05:40:42 -05:00
|
|
|
|
2014-05-14 11:04:25 -04:00
|
|
|
it "should call the callback", ->
|
|
|
|
@callback.called.should.equal true
|