overleaf/services/document-updater/test/unit/coffee/PersistenceManager/setDocTests.coffee

39 lines
1.2 KiB
CoffeeScript
Raw Normal View History

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()
"logger-sharelatex": @logger = {warn: sinon.stub()}
2014-02-12 05:40:42 -05: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
@PersistenceManager.setDocInWeb = sinon.stub().callsArg(3)
@PersistenceManager.setDocVersionInMongo = sinon.stub().callsArg(2)
2014-02-12 05:40:42 -05:00
@PersistenceManager.setDoc @project_id, @doc_id, @lines, @version, @callback
2014-02-12 05:40:42 -05:00
it "should set the doc in the web api", ->
@PersistenceManager.setDocInWeb
.calledWith(@project_id, @doc_id, @lines)
.should.equal true
2014-02-12 05:40:42 -05: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
it "should call the callback", ->
@callback.called.should.equal true