mirror of
https://github.com/overleaf/overleaf.git
synced 2024-10-31 21:21:03 -04:00
75 lines
2.4 KiB
CoffeeScript
75 lines
2.4 KiB
CoffeeScript
sinon = require('sinon')
|
|
chai = require('chai')
|
|
should = chai.should()
|
|
modulePath = "../../../../app/js/DocumentManager.js"
|
|
SandboxedModule = require('sandboxed-module')
|
|
|
|
describe "DocumentUpdater - getDoc", ->
|
|
beforeEach ->
|
|
@DocumentManager = SandboxedModule.require modulePath, requires:
|
|
"./RedisManager": @RedisManager = {}
|
|
"./PersistenceManager": @PersistenceManager = {}
|
|
"./DocOpsManager": @DocOpsManager = {}
|
|
"logger-sharelatex": @logger = {log: sinon.stub()}
|
|
"./Metrics": @Metrics =
|
|
Timer: class Timer
|
|
done: sinon.stub()
|
|
|
|
@project_id = "project-id-123"
|
|
@doc_id = "doc-id-123"
|
|
@lines = ["one", "two", "three"]
|
|
@version = 42
|
|
@callback = sinon.stub()
|
|
|
|
describe "when the doc exists in Redis", ->
|
|
beforeEach ->
|
|
@RedisManager.getDoc = sinon.stub().callsArgWith(1, null, @lines, @version)
|
|
@DocumentManager.getDoc @project_id, @doc_id, @callback
|
|
|
|
it "should get the doc from Redis", ->
|
|
@RedisManager.getDoc
|
|
.calledWith(@doc_id)
|
|
.should.equal true
|
|
|
|
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
|
|
|
|
describe "when the doc does not exist in Redis", ->
|
|
beforeEach ->
|
|
@RedisManager.getDoc = sinon.stub().callsArgWith(1, null, null, null)
|
|
@PersistenceManager.getDoc = sinon.stub().callsArgWith(2, null, @lines)
|
|
@DocOpsManager.getDocVersionInMongo = sinon.stub().callsArgWith(1, null, @version)
|
|
@RedisManager.putDocInMemory = sinon.stub().callsArg(4)
|
|
@DocumentManager.getDoc @project_id, @doc_id, @callback
|
|
|
|
it "should try to get the doc from Redis", ->
|
|
@RedisManager.getDoc
|
|
.calledWith(@doc_id)
|
|
.should.equal true
|
|
|
|
it "should get the doc version from Mongo", ->
|
|
@DocOpsManager.getDocVersionInMongo
|
|
.calledWith(@doc_id)
|
|
.should.equal true
|
|
|
|
it "should get the doc from the PersistenceManager", ->
|
|
@PersistenceManager.getDoc
|
|
.calledWith(@project_id, @doc_id)
|
|
.should.equal true
|
|
|
|
it "should set the doc in Redis", ->
|
|
@RedisManager.putDocInMemory
|
|
.calledWith(@project_id, @doc_id, @lines, @version)
|
|
.should.equal true
|
|
|
|
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
|
|
|
|
|
|
|