mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-28 18:40:48 +00:00
ffd10a8439
The version number is only used by the doc updater and so can be cleanly encapsulated in a collection that only the doc updater knows about. The version is already stored under docOps, so continue to tore it there.
46 lines
No EOL
1.5 KiB
CoffeeScript
46 lines
No EOL
1.5 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
|
|
|
|
@doc_id = ObjectId().toString()
|
|
@callback = sinon.stub()
|
|
|
|
describe "getDocVersionInMongo", ->
|
|
describe "when the doc exists", ->
|
|
beforeEach ->
|
|
@doc =
|
|
version: @version = 42
|
|
@db.docOps.find = sinon.stub().callsArgWith(2, null, [@doc])
|
|
@PersistenceManager.getDocVersionInMongo @doc_id, @callback
|
|
|
|
it "should look for the doc in the database", ->
|
|
@db.docOps.find
|
|
.calledWith({ doc_id: ObjectId(@doc_id) }, {version: 1})
|
|
.should.equal true
|
|
|
|
it "should call the callback with the version", ->
|
|
@callback.calledWith(null, @version).should.equal true
|
|
|
|
describe "when the doc doesn't exist", ->
|
|
beforeEach ->
|
|
@db.docOps.find = sinon.stub().callsArgWith(2, null, [])
|
|
@PersistenceManager.getDocVersionInMongo @doc_id, @callback
|
|
|
|
it "should call the callback with 0", ->
|
|
@callback.calledWith(null, 0).should.equal true |