mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-29 17:43:42 -05:00
add unit tests
This commit is contained in:
parent
152a25e96d
commit
a72d228354
3 changed files with 106 additions and 0 deletions
|
@ -467,3 +467,42 @@ describe "DocumentManager", ->
|
||||||
|
|
||||||
it "should call the callback", ->
|
it "should call the callback", ->
|
||||||
@callback.called.should.equal true
|
@callback.called.should.equal true
|
||||||
|
|
||||||
|
describe "resyncDocContents", ->
|
||||||
|
describe "when doc is loaded in redis", ->
|
||||||
|
beforeEach ->
|
||||||
|
@RedisManager.getDoc = sinon.stub().callsArgWith(2, null, @lines, @version, @ranges, @pathname)
|
||||||
|
@RedisManager.queueResyncDocContents = sinon.stub()
|
||||||
|
@DocumentManager.resyncDocContents @project_id, @doc_id, @callback
|
||||||
|
|
||||||
|
it "gets the doc contents from redis", ->
|
||||||
|
@RedisManager.getDoc
|
||||||
|
.calledWith(@project_id, @doc_id)
|
||||||
|
.should.equal true
|
||||||
|
|
||||||
|
it "queues a resync doc content update", ->
|
||||||
|
@RedisManager.queueResyncDocContents
|
||||||
|
.calledWith(@project_id, @doc_id, @lines, @version, @pathname, @callback)
|
||||||
|
.should.equal true
|
||||||
|
|
||||||
|
describe "when doc is not loaded in redis", ->
|
||||||
|
beforeEach ->
|
||||||
|
@RedisManager.getDoc = sinon.stub().callsArgWith(2, null)
|
||||||
|
@PersistenceManager.getDoc = sinon.stub().callsArgWith(2, null, @lines, @version, @ranges, @pathname)
|
||||||
|
@RedisManager.queueResyncDocContents = sinon.stub()
|
||||||
|
@DocumentManager.resyncDocContents @project_id, @doc_id, @callback
|
||||||
|
|
||||||
|
it "tries to get the doc contents from redis", ->
|
||||||
|
@RedisManager.getDoc
|
||||||
|
.calledWith(@project_id, @doc_id)
|
||||||
|
.should.equal true
|
||||||
|
|
||||||
|
it "gets the doc contents from web", ->
|
||||||
|
@PersistenceManager.getDoc
|
||||||
|
.calledWith(@project_id, @doc_id)
|
||||||
|
.should.equal true
|
||||||
|
|
||||||
|
it "queues a resync doc content update", ->
|
||||||
|
@RedisManager.queueResyncDocContents
|
||||||
|
.calledWith(@project_id, @doc_id, @lines, @version, @pathname, @callback)
|
||||||
|
.should.equal true
|
||||||
|
|
|
@ -16,7 +16,9 @@ describe "HistoryManager", ->
|
||||||
url: "http://trackchanges.example.com"
|
url: "http://trackchanges.example.com"
|
||||||
}
|
}
|
||||||
"logger-sharelatex": @logger = { log: sinon.stub(), error: sinon.stub() }
|
"logger-sharelatex": @logger = { log: sinon.stub(), error: sinon.stub() }
|
||||||
|
"./DocumentManager": @DocumentManager = {}
|
||||||
"./HistoryRedisManager": @HistoryRedisManager = {}
|
"./HistoryRedisManager": @HistoryRedisManager = {}
|
||||||
|
"./RedisManager": @RedisManager = {}
|
||||||
@project_id = "mock-project-id"
|
@project_id = "mock-project-id"
|
||||||
@doc_id = "mock-doc-id"
|
@doc_id = "mock-doc-id"
|
||||||
@callback = sinon.stub()
|
@callback = sinon.stub()
|
||||||
|
@ -158,3 +160,32 @@ describe "HistoryManager", ->
|
||||||
# Previously we were on 16 ops
|
# Previously we were on 16 ops
|
||||||
# We didn't pass over a multiple of 5
|
# We didn't pass over a multiple of 5
|
||||||
@HistoryManager.shouldFlushHistoryOps(17, ['a', 'b', 'c'].length, 5).should.equal true
|
@HistoryManager.shouldFlushHistoryOps(17, ['a', 'b', 'c'].length, 5).should.equal true
|
||||||
|
|
||||||
|
describe "resyncProjectHistory", ->
|
||||||
|
beforeEach ->
|
||||||
|
@docs = [
|
||||||
|
doc: @doc_id
|
||||||
|
path: 'main.tex'
|
||||||
|
]
|
||||||
|
@files = [
|
||||||
|
file: 'mock-file-id'
|
||||||
|
path: 'universe.png'
|
||||||
|
url: "www.filestore.test/#{@project_id}/mock-file-id"
|
||||||
|
]
|
||||||
|
@RedisManager.queueResyncProjectStructure = sinon.stub().yields()
|
||||||
|
@DocumentManager.resyncDocContentsWithLock = sinon.stub().yields()
|
||||||
|
@HistoryManager.resyncProjectHistory @project_id, @docs, @files, @callback
|
||||||
|
|
||||||
|
it "should queue a project structure reync", ->
|
||||||
|
@RedisManager.queueResyncProjectStructure
|
||||||
|
.calledWith(@project_id, @docs, @files)
|
||||||
|
.should.equal true
|
||||||
|
|
||||||
|
it "should queue doc content reyncs", ->
|
||||||
|
@DocumentManager
|
||||||
|
.resyncDocContentsWithLock
|
||||||
|
.calledWith(@project_id, @doc_id)
|
||||||
|
.should.equal true
|
||||||
|
|
||||||
|
it "should call the callback", ->
|
||||||
|
@callback.called.should.equal true
|
||||||
|
|
|
@ -544,3 +544,39 @@ describe "HttpController", ->
|
||||||
@next
|
@next
|
||||||
.calledWith(new Error("oops"))
|
.calledWith(new Error("oops"))
|
||||||
.should.equal true
|
.should.equal true
|
||||||
|
|
||||||
|
describe "resyncProjectHistory", ->
|
||||||
|
beforeEach ->
|
||||||
|
@docs = sinon.stub()
|
||||||
|
@files = sinon.stub()
|
||||||
|
@fileUpdates = sinon.stub()
|
||||||
|
@req =
|
||||||
|
body:
|
||||||
|
{@docs, @files}
|
||||||
|
params:
|
||||||
|
project_id: @project_id
|
||||||
|
|
||||||
|
describe "successfully", ->
|
||||||
|
beforeEach ->
|
||||||
|
@HistoryManager.resyncProjectHistory = sinon.stub().callsArg(3)
|
||||||
|
@HttpController.resyncProjectHistory(@req, @res, @next)
|
||||||
|
|
||||||
|
it "should accept the change", ->
|
||||||
|
@HistoryManager.resyncProjectHistory
|
||||||
|
.calledWith(@project_id, @docs, @files)
|
||||||
|
.should.equal true
|
||||||
|
|
||||||
|
it "should return a successful No Content response", ->
|
||||||
|
@res.send
|
||||||
|
.calledWith(204)
|
||||||
|
.should.equal true
|
||||||
|
|
||||||
|
describe "when an errors occurs", ->
|
||||||
|
beforeEach ->
|
||||||
|
@HistoryManager.resyncProjectHistory = sinon.stub().callsArgWith(3, new Error("oops"))
|
||||||
|
@HttpController.resyncProjectHistory(@req, @res, @next)
|
||||||
|
|
||||||
|
it "should call next with the error", ->
|
||||||
|
@next
|
||||||
|
.calledWith(new Error("oops"))
|
||||||
|
.should.equal true
|
||||||
|
|
Loading…
Reference in a new issue