|
@@ -3,6 +3,7 @@ chai = require('chai')
|
|
|
should = chai.should()
|
|
should = chai.should()
|
|
|
modulePath = "../../../../app/js/ProjectManager.js"
|
|
modulePath = "../../../../app/js/ProjectManager.js"
|
|
|
SandboxedModule = require('sandboxed-module')
|
|
SandboxedModule = require('sandboxed-module')
|
|
|
|
|
+_ = require('underscore')
|
|
|
|
|
|
|
|
describe "ProjectManager", ->
|
|
describe "ProjectManager", ->
|
|
|
beforeEach ->
|
|
beforeEach ->
|
|
@@ -18,6 +19,7 @@ describe "ProjectManager", ->
|
|
|
|
|
|
|
|
@project_id = "project-id-123"
|
|
@project_id = "project-id-123"
|
|
|
@user_id = "user-id-123"
|
|
@user_id = "user-id-123"
|
|
|
|
|
+ @version = 1234567
|
|
|
@HistoryManager.shouldFlushHistoryOps = sinon.stub().returns(false)
|
|
@HistoryManager.shouldFlushHistoryOps = sinon.stub().returns(false)
|
|
|
@HistoryManager.flushProjectChangesAsync = sinon.stub()
|
|
@HistoryManager.flushProjectChangesAsync = sinon.stub()
|
|
|
@callback = sinon.stub()
|
|
@callback = sinon.stub()
|
|
@@ -45,19 +47,22 @@ describe "ProjectManager", ->
|
|
|
|
|
|
|
|
describe "successfully", ->
|
|
describe "successfully", ->
|
|
|
beforeEach ->
|
|
beforeEach ->
|
|
|
- @ProjectManager.updateProjectWithLocks @project_id, @user_id, @docUpdates, @fileUpdates, @callback
|
|
|
|
|
|
|
+ @ProjectManager.updateProjectWithLocks @project_id, @user_id, @docUpdates, @fileUpdates, @version, @callback
|
|
|
|
|
|
|
|
it "should rename the docs in the updates", ->
|
|
it "should rename the docs in the updates", ->
|
|
|
|
|
+ firstDocUpdateWithVersion = _.extend({}, @firstDocUpdate, {version: "#{@version}.0"})
|
|
|
|
|
+ secondDocUpdateWithVersion = _.extend({}, @secondDocUpdate, {version: "#{@version}.1"})
|
|
|
@DocumentManager.renameDocWithLock
|
|
@DocumentManager.renameDocWithLock
|
|
|
- .calledWith(@project_id, @firstDocUpdate.id, @user_id, @firstDocUpdate)
|
|
|
|
|
|
|
+ .calledWith(@project_id, @firstDocUpdate.id, @user_id, firstDocUpdateWithVersion)
|
|
|
.should.equal true
|
|
.should.equal true
|
|
|
@DocumentManager.renameDocWithLock
|
|
@DocumentManager.renameDocWithLock
|
|
|
- .calledWith(@project_id, @secondDocUpdate.id, @user_id, @secondDocUpdate)
|
|
|
|
|
|
|
+ .calledWith(@project_id, @secondDocUpdate.id, @user_id, secondDocUpdateWithVersion)
|
|
|
.should.equal true
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should rename the files in the updates", ->
|
|
it "should rename the files in the updates", ->
|
|
|
|
|
+ firstFileUpdateWithVersion = _.extend({}, @firstFileUpdate, {version: "#{@version}.2"})
|
|
|
@ProjectHistoryRedisManager.queueRenameEntity
|
|
@ProjectHistoryRedisManager.queueRenameEntity
|
|
|
- .calledWith(@project_id, 'file', @firstFileUpdate.id, @user_id, @firstFileUpdate)
|
|
|
|
|
|
|
+ .calledWith(@project_id, 'file', @firstFileUpdate.id, @user_id, firstFileUpdateWithVersion)
|
|
|
.should.equal true
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should not flush the history", ->
|
|
it "should not flush the history", ->
|
|
@@ -72,7 +77,7 @@ describe "ProjectManager", ->
|
|
|
beforeEach ->
|
|
beforeEach ->
|
|
|
@error = new Error('error')
|
|
@error = new Error('error')
|
|
|
@DocumentManager.renameDocWithLock = sinon.stub().yields(@error)
|
|
@DocumentManager.renameDocWithLock = sinon.stub().yields(@error)
|
|
|
- @ProjectManager.updateProjectWithLocks @project_id, @user_id, @docUpdates, @fileUpdates, @callback
|
|
|
|
|
|
|
+ @ProjectManager.updateProjectWithLocks @project_id, @user_id, @docUpdates, @fileUpdates, @version, @callback
|
|
|
|
|
|
|
|
it "should call the callback with the error", ->
|
|
it "should call the callback with the error", ->
|
|
|
@callback.calledWith(@error).should.equal true
|
|
@callback.calledWith(@error).should.equal true
|
|
@@ -81,7 +86,7 @@ describe "ProjectManager", ->
|
|
|
beforeEach ->
|
|
beforeEach ->
|
|
|
@error = new Error('error')
|
|
@error = new Error('error')
|
|
|
@ProjectHistoryRedisManager.queueRenameEntity = sinon.stub().yields(@error)
|
|
@ProjectHistoryRedisManager.queueRenameEntity = sinon.stub().yields(@error)
|
|
|
- @ProjectManager.updateProjectWithLocks @project_id, @user_id, @docUpdates, @fileUpdates, @callback
|
|
|
|
|
|
|
+ @ProjectManager.updateProjectWithLocks @project_id, @user_id, @docUpdates, @fileUpdates, @version, @callback
|
|
|
|
|
|
|
|
it "should call the callback with the error", ->
|
|
it "should call the callback with the error", ->
|
|
|
@callback.calledWith(@error).should.equal true
|
|
@callback.calledWith(@error).should.equal true
|
|
@@ -89,7 +94,7 @@ describe "ProjectManager", ->
|
|
|
describe "with enough ops to flush", ->
|
|
describe "with enough ops to flush", ->
|
|
|
beforeEach ->
|
|
beforeEach ->
|
|
|
@HistoryManager.shouldFlushHistoryOps = sinon.stub().returns(true)
|
|
@HistoryManager.shouldFlushHistoryOps = sinon.stub().returns(true)
|
|
|
- @ProjectManager.updateProjectWithLocks @project_id, @user_id, @docUpdates, @fileUpdates, @callback
|
|
|
|
|
|
|
+ @ProjectManager.updateProjectWithLocks @project_id, @user_id, @docUpdates, @fileUpdates, @version, @callback
|
|
|
|
|
|
|
|
it "should flush the history", ->
|
|
it "should flush the history", ->
|
|
|
@HistoryManager.flushProjectChangesAsync
|
|
@HistoryManager.flushProjectChangesAsync
|
|
@@ -106,26 +111,36 @@ describe "ProjectManager", ->
|
|
|
docLines: "a\nb"
|
|
docLines: "a\nb"
|
|
|
@docUpdates = [ @firstDocUpdate, @secondDocUpdate ]
|
|
@docUpdates = [ @firstDocUpdate, @secondDocUpdate ]
|
|
|
@firstFileUpdate =
|
|
@firstFileUpdate =
|
|
|
- id: 2
|
|
|
|
|
|
|
+ id: 3
|
|
|
url: 'filestore.example.com/2'
|
|
url: 'filestore.example.com/2'
|
|
|
- @fileUpdates = [ @firstFileUpdate ]
|
|
|
|
|
|
|
+ @secondFileUpdate =
|
|
|
|
|
+ id: 4
|
|
|
|
|
+ url: 'filestore.example.com/3'
|
|
|
|
|
+ @fileUpdates = [ @firstFileUpdate, @secondFileUpdate ]
|
|
|
@ProjectHistoryRedisManager.queueAddEntity = sinon.stub().yields()
|
|
@ProjectHistoryRedisManager.queueAddEntity = sinon.stub().yields()
|
|
|
|
|
|
|
|
describe "successfully", ->
|
|
describe "successfully", ->
|
|
|
beforeEach ->
|
|
beforeEach ->
|
|
|
- @ProjectManager.updateProjectWithLocks @project_id, @user_id, @docUpdates, @fileUpdates, @callback
|
|
|
|
|
|
|
+ @ProjectManager.updateProjectWithLocks @project_id, @user_id, @docUpdates, @fileUpdates, @version, @callback
|
|
|
|
|
|
|
|
it "should add the docs in the updates", ->
|
|
it "should add the docs in the updates", ->
|
|
|
- @ProjectHistoryRedisManager.queueAddEntity
|
|
|
|
|
- .calledWith(@project_id, 'doc', @firstDocUpdate.id, @user_id, @firstDocUpdate)
|
|
|
|
|
|
|
+ firstDocUpdateWithVersion = _.extend({}, @firstDocUpdate, {version: "#{@version}.0"})
|
|
|
|
|
+ secondDocUpdateWithVersion = _.extend({}, @secondDocUpdate, {version: "#{@version}.1"})
|
|
|
|
|
+ @ProjectHistoryRedisManager.queueAddEntity.getCall(0)
|
|
|
|
|
+ .calledWith(@project_id, 'doc', @firstDocUpdate.id, @user_id, firstDocUpdateWithVersion)
|
|
|
.should.equal true
|
|
.should.equal true
|
|
|
- @ProjectHistoryRedisManager.queueAddEntity
|
|
|
|
|
- .calledWith(@project_id, 'doc', @secondDocUpdate.id, @user_id, @secondDocUpdate)
|
|
|
|
|
|
|
+ @ProjectHistoryRedisManager.queueAddEntity.getCall(1)
|
|
|
|
|
+ .calledWith(@project_id, 'doc', @secondDocUpdate.id, @user_id, secondDocUpdateWithVersion)
|
|
|
.should.equal true
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should add the files in the updates", ->
|
|
it "should add the files in the updates", ->
|
|
|
- @ProjectHistoryRedisManager.queueAddEntity
|
|
|
|
|
- .calledWith(@project_id, 'file', @firstFileUpdate.id, @user_id, @firstFileUpdate)
|
|
|
|
|
|
|
+ firstFileUpdateWithVersion = _.extend({}, @firstFileUpdate, {version: "#{@version}.2"})
|
|
|
|
|
+ secondFileUpdateWithVersion = _.extend({}, @secondFileUpdate, {version: "#{@version}.3"})
|
|
|
|
|
+ @ProjectHistoryRedisManager.queueAddEntity.getCall(2)
|
|
|
|
|
+ .calledWith(@project_id, 'file', @firstFileUpdate.id, @user_id, firstFileUpdateWithVersion)
|
|
|
|
|
+ .should.equal true
|
|
|
|
|
+ @ProjectHistoryRedisManager.queueAddEntity.getCall(3)
|
|
|
|
|
+ .calledWith(@project_id, 'file', @secondFileUpdate.id, @user_id, secondFileUpdateWithVersion)
|
|
|
.should.equal true
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should not flush the history", ->
|
|
it "should not flush the history", ->
|
|
@@ -140,7 +155,7 @@ describe "ProjectManager", ->
|
|
|
beforeEach ->
|
|
beforeEach ->
|
|
|
@error = new Error('error')
|
|
@error = new Error('error')
|
|
|
@ProjectHistoryRedisManager.queueAddEntity = sinon.stub().yields(@error)
|
|
@ProjectHistoryRedisManager.queueAddEntity = sinon.stub().yields(@error)
|
|
|
- @ProjectManager.updateProjectWithLocks @project_id, @user_id, @docUpdates, @fileUpdates, @callback
|
|
|
|
|
|
|
+ @ProjectManager.updateProjectWithLocks @project_id, @user_id, @docUpdates, @fileUpdates, @version, @callback
|
|
|
|
|
|
|
|
it "should call the callback with the error", ->
|
|
it "should call the callback with the error", ->
|
|
|
@callback.calledWith(@error).should.equal true
|
|
@callback.calledWith(@error).should.equal true
|
|
@@ -149,7 +164,7 @@ describe "ProjectManager", ->
|
|
|
beforeEach ->
|
|
beforeEach ->
|
|
|
@error = new Error('error')
|
|
@error = new Error('error')
|
|
|
@ProjectHistoryRedisManager.queueAddEntity = sinon.stub().yields(@error)
|
|
@ProjectHistoryRedisManager.queueAddEntity = sinon.stub().yields(@error)
|
|
|
- @ProjectManager.updateProjectWithLocks @project_id, @user_id, @docUpdates, @fileUpdates, @callback
|
|
|
|
|
|
|
+ @ProjectManager.updateProjectWithLocks @project_id, @user_id, @docUpdates, @fileUpdates, @version, @callback
|
|
|
|
|
|
|
|
it "should call the callback with the error", ->
|
|
it "should call the callback with the error", ->
|
|
|
@callback.calledWith(@error).should.equal true
|
|
@callback.calledWith(@error).should.equal true
|
|
@@ -157,7 +172,7 @@ describe "ProjectManager", ->
|
|
|
describe "with enough ops to flush", ->
|
|
describe "with enough ops to flush", ->
|
|
|
beforeEach ->
|
|
beforeEach ->
|
|
|
@HistoryManager.shouldFlushHistoryOps = sinon.stub().returns(true)
|
|
@HistoryManager.shouldFlushHistoryOps = sinon.stub().returns(true)
|
|
|
- @ProjectManager.updateProjectWithLocks @project_id, @user_id, @docUpdates, @fileUpdates, @callback
|
|
|
|
|
|
|
+ @ProjectManager.updateProjectWithLocks @project_id, @user_id, @docUpdates, @fileUpdates, @version, @callback
|
|
|
|
|
|
|
|
it "should flush the history", ->
|
|
it "should flush the history", ->
|
|
|
@HistoryManager.flushProjectChangesAsync
|
|
@HistoryManager.flushProjectChangesAsync
|