Fix and extend unit tests

This commit is contained in:
James Allen 2018-02-15 15:55:12 +00:00
parent 6c57317f8d
commit f6c79f3203
4 changed files with 37 additions and 0 deletions

View file

@ -10,6 +10,7 @@ describe "ProjectManager - flushAndDeleteProject", ->
"./RedisManager": @RedisManager = {}
"./DocumentManager": @DocumentManager = {}
"logger-sharelatex": @logger = { log: sinon.stub(), error: sinon.stub() }
"./HistoryManager": @HistoryManager = {}
"./Metrics": @Metrics =
Timer: class Timer
done: sinon.stub()

View file

@ -10,6 +10,7 @@ describe "ProjectManager - flushProject", ->
"./RedisManager": @RedisManager = {}
"./DocumentManager": @DocumentManager = {}
"logger-sharelatex": @logger = { log: sinon.stub(), error: sinon.stub() }
"./HistoryManager": @HistoryManager = {}
"./Metrics": @Metrics =
Timer: class Timer
done: sinon.stub()

View file

@ -11,6 +11,7 @@ describe "ProjectManager - getProjectDocsAndFlushIfOld", ->
"./RedisManager": @RedisManager = {}
"./DocumentManager": @DocumentManager = {}
"logger-sharelatex": @logger = { log: sinon.stub(), error: sinon.stub() }
"./HistoryManager": @HistoryManager = {}
"./Metrics": @Metrics =
Timer: class Timer
done: sinon.stub()

View file

@ -10,17 +10,21 @@ describe "ProjectManager", ->
"./RedisManager": @RedisManager = {}
"./DocumentManager": @DocumentManager = {}
"logger-sharelatex": @logger = { log: sinon.stub(), error: sinon.stub() }
"./HistoryManager": @HistoryManager = {}
"./Metrics": @Metrics =
Timer: class Timer
done: sinon.stub()
@project_id = "project-id-123"
@user_id = "user-id-123"
@HistoryManager.shouldFlushHistoryOps = sinon.stub().returns(false)
@HistoryManager.flushProjectChangesAsync = sinon.stub()
@callback = sinon.stub()
describe "updateProjectWithLocks", ->
describe "rename operations", ->
beforeEach ->
@firstDocUpdate =
id: 1
pathname: 'foo'
@ -55,6 +59,11 @@ describe "ProjectManager", ->
.calledWith(@project_id, @firstFileUpdate.id, @user_id, @firstFileUpdate)
.should.equal true
it "should not flush the history", ->
@HistoryManager.flushProjectChangesAsync
.calledWith(@project_id)
.should.equal false
it "should call the callback", ->
@callback.called.should.equal true
@ -76,6 +85,16 @@ describe "ProjectManager", ->
it "should call the callback with the error", ->
@callback.calledWith(@error).should.equal true
describe "with enough ops to flush", ->
beforeEach ->
@HistoryManager.shouldFlushHistoryOps = sinon.stub().returns(true)
@ProjectManager.updateProjectWithLocks @project_id, @user_id, @docUpdates, @fileUpdates, @callback
it "should flush the history", ->
@HistoryManager.flushProjectChangesAsync
.calledWith(@project_id)
.should.equal true
describe "add operations", ->
beforeEach ->
@firstDocUpdate =
@ -108,6 +127,11 @@ describe "ProjectManager", ->
.calledWith(@project_id, 'file', @firstFileUpdate.id, @user_id, @firstFileUpdate)
.should.equal true
it "should not flush the history", ->
@HistoryManager.flushProjectChangesAsync
.calledWith(@project_id)
.should.equal false
it "should call the callback", ->
@callback.called.should.equal true
@ -129,3 +153,13 @@ describe "ProjectManager", ->
it "should call the callback with the error", ->
@callback.calledWith(@error).should.equal true
describe "with enough ops to flush", ->
beforeEach ->
@HistoryManager.shouldFlushHistoryOps = sinon.stub().returns(true)
@ProjectManager.updateProjectWithLocks @project_id, @user_id, @docUpdates, @fileUpdates, @callback
it "should flush the history", ->
@HistoryManager.flushProjectChangesAsync
.calledWith(@project_id)
.should.equal true