mirror of
https://github.com/overleaf/overleaf.git
synced 2024-10-31 21:21:03 -04:00
44 lines
1.2 KiB
CoffeeScript
44 lines
1.2 KiB
CoffeeScript
sinon = require('sinon')
|
|
chai = require('chai')
|
|
should = chai.should()
|
|
modulePath = "../../../../app/js/PersistenceManager.js"
|
|
SandboxedModule = require('sandboxed-module')
|
|
Errors = require "../../../../app/js/Errors"
|
|
{ObjectId} = require("mongojs")
|
|
|
|
describe "PersistenceManager.getDocVersionInMongo", ->
|
|
beforeEach ->
|
|
@PersistenceManager = SandboxedModule.require modulePath, requires:
|
|
"request": @request = sinon.stub()
|
|
"settings-sharelatex": @Settings = {}
|
|
"./Metrics": @Metrics =
|
|
Timer: class Timer
|
|
done: sinon.stub()
|
|
"./mongojs":
|
|
db: @db = { docOps: {} }
|
|
ObjectId: ObjectId
|
|
"logger-sharelatex": @logger = {log: sinon.stub(), err: sinon.stub()}
|
|
|
|
@doc_id = ObjectId().toString()
|
|
@callback = sinon.stub()
|
|
|
|
describe "setDocVersionInMongo", ->
|
|
beforeEach ->
|
|
@version = 42
|
|
@db.docOps.update = sinon.stub().callsArg(3)
|
|
@PersistenceManager.setDocVersionInMongo @doc_id, @version, @callback
|
|
|
|
it "should update the doc version", ->
|
|
@db.docOps.update
|
|
.calledWith({
|
|
doc_id: ObjectId(@doc_id)
|
|
}, {
|
|
$set:
|
|
version: @version
|
|
}, {
|
|
upsert: true
|
|
})
|
|
.should.equal true
|
|
|
|
it "should call the callback", ->
|
|
@callback.called.should.equal true
|