overleaf/services/document-updater/test/unit/coffee/DocumentManager/getDocAndRecentOpsTests.coffee

68 lines
2.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/DocumentManager.js"
SandboxedModule = require('sandboxed-module')
describe "DocumentManager.getDocAndRecentOps", ->
2014-02-12 05:40:42 -05:00
beforeEach ->
@DocumentManager = SandboxedModule.require modulePath, requires:
"./RedisManager": @RedisManager = {}
"./PersistenceManager": @PersistenceManager = {}
"logger-sharelatex": @logger = {log: sinon.stub()}
"./Metrics": @Metrics =
Timer: class Timer
done: sinon.stub()
"./TrackChangesManager": {}
2014-02-12 05:40:42 -05:00
@project_id = "project-id-123"
@doc_id = "doc-id-123"
@lines = ["one", "two", "three"]
@version = 42
@fromVersion = 40
@ops = ["mock-op-1", "mock-op-2"]
@callback = sinon.stub()
describe "with a previous version specified", ->
beforeEach ->
@DocumentManager.getDoc = sinon.stub().callsArgWith(2, null, @lines, @version)
@RedisManager.getPreviousDocOps = sinon.stub().callsArgWith(3, null, @ops)
2014-02-12 05:40:42 -05:00
@DocumentManager.getDocAndRecentOps @project_id, @doc_id, @fromVersion, @callback
it "should get the doc", ->
@DocumentManager.getDoc
.calledWith(@project_id, @doc_id)
.should.equal true
it "should get the doc ops", ->
@RedisManager.getPreviousDocOps
.calledWith(@doc_id, @fromVersion, @version)
2014-02-12 05:40:42 -05:00
.should.equal true
it "should call the callback with the doc info", ->
@callback.calledWith(null, @lines, @version, @ops).should.equal true
it "should time the execution", ->
@Metrics.Timer::done.called.should.equal true
describe "with no previous version specified", ->
beforeEach ->
@DocumentManager.getDoc = sinon.stub().callsArgWith(2, null, @lines, @version)
@RedisManager.getPreviousDocOps = sinon.stub().callsArgWith(3, null, @ops)
2014-02-12 05:40:42 -05:00
@DocumentManager.getDocAndRecentOps @project_id, @doc_id, -1, @callback
it "should get the doc", ->
@DocumentManager.getDoc
.calledWith(@project_id, @doc_id)
.should.equal true
it "should not need to get the doc ops", ->
@RedisManager.getPreviousDocOps.called.should.equal false
2014-02-12 05:40:42 -05:00
it "should call the callback with the doc info", ->
@callback.calledWith(null, @lines, @version, []).should.equal true
it "should time the execution", ->
@Metrics.Timer::done.called.should.equal true