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')
|
2014-05-14 08:28:17 -04:00
|
|
|
{ObjectId} = require("mongojs")
|
2014-02-12 05:40:42 -05:00
|
|
|
|
|
|
|
describe "PersistenceManager.getDoc", ->
|
|
|
|
beforeEach ->
|
|
|
|
@PersistenceManager = SandboxedModule.require modulePath, requires:
|
|
|
|
"request": @request = sinon.stub()
|
|
|
|
"settings-sharelatex": @Settings = {}
|
|
|
|
"./Metrics": @Metrics =
|
|
|
|
Timer: class Timer
|
|
|
|
done: sinon.stub()
|
2014-05-14 09:16:27 -04:00
|
|
|
"logger-sharelatex": @logger = {warn: sinon.stub()}
|
2014-05-14 08:28:17 -04:00
|
|
|
"./mongojs":
|
|
|
|
db: @db = { docOps: {} }
|
|
|
|
ObjectId: ObjectId
|
|
|
|
|
|
|
|
@project_id = ObjectId().toString()
|
|
|
|
@doc_id = ObjectId().toString()
|
2014-02-12 05:40:42 -05:00
|
|
|
@callback = sinon.stub()
|
2014-05-14 08:28:17 -04:00
|
|
|
@lines = ["mock", "doc", "lines"]
|
|
|
|
@version = 42
|
2014-02-12 05:40:42 -05:00
|
|
|
|
2014-05-15 06:13:16 -04:00
|
|
|
describe "successfully", ->
|
2014-02-12 05:40:42 -05:00
|
|
|
beforeEach ->
|
2014-05-15 06:13:16 -04:00
|
|
|
@PersistenceManager.getDocFromWeb = sinon.stub().callsArgWith(2, null, @lines)
|
|
|
|
@PersistenceManager.getDocVersionInMongo = sinon.stub().callsArgWith(1, null, @version)
|
2014-05-14 08:28:17 -04:00
|
|
|
@PersistenceManager.getDoc @project_id, @doc_id, @callback
|
2014-02-12 05:40:42 -05:00
|
|
|
|
2014-05-14 08:28:17 -04:00
|
|
|
it "should look up the doc in the web api", ->
|
|
|
|
@PersistenceManager.getDocFromWeb
|
|
|
|
.calledWith(@project_id, @doc_id)
|
2014-02-12 05:40:42 -05:00
|
|
|
.should.equal true
|
|
|
|
|
2014-05-14 11:04:25 -04:00
|
|
|
it "should look up the version in Mongo", ->
|
2014-05-14 08:28:17 -04:00
|
|
|
@PersistenceManager.getDocVersionInMongo
|
2014-05-14 11:04:25 -04:00
|
|
|
.calledWith(@doc_id)
|
|
|
|
.should.equal true
|
2014-02-12 05:40:42 -05:00
|
|
|
|
2014-05-14 08:28:17 -04:00
|
|
|
it "should call the callback with the lines and version", ->
|
|
|
|
@callback.calledWith(null, @lines, @version).should.equal true
|
2014-02-12 05:40:42 -05:00
|
|
|
|
|
|
|
|