mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 22:23:42 +01:00
Merge pull request #1282 from sharelatex/ew-collabratec-support-imported-projects
Support importing projects with collabratec users to v2 GitOrigin-RevId: 2dd3781dde158cdab6bf95138311224a032ab8a4
This commit is contained in:
committed by
sharelatex
parent
740dce07a9
commit
bfeefe8406
@@ -15,6 +15,7 @@ describe "ProjectCollabratecDetailsHandler", ->
|
||||
beforeEach ->
|
||||
@projectId = ObjectId("5bea8747c7bba6012fcaceb3")
|
||||
@userId = ObjectId("5be316a9c7f6aa03802ea8fb")
|
||||
@userId2 = ObjectId("5c1794b3f0e89b1d1c577eca")
|
||||
@ProjectModel = {}
|
||||
@ProjectCollabratecDetailsHandler = SandboxedModule.require modulePath, requires:
|
||||
"../../models/Project": { Project: @ProjectModel }
|
||||
@@ -140,6 +141,63 @@ describe "ProjectCollabratecDetailsHandler", ->
|
||||
it "should callback with error", ->
|
||||
expect(@callback.firstCall.args[0]).to.be.instanceOf Error
|
||||
|
||||
describe "setCollabratecUsers", ->
|
||||
beforeEach ->
|
||||
@collabratecUsers = [
|
||||
{
|
||||
user_id: @userId
|
||||
collabratec_document_id: "collabratec-document-id-1"
|
||||
collabratec_privategroup_id: "collabratec-private-group-id-1"
|
||||
},
|
||||
{
|
||||
user_id: @userId2
|
||||
collabratec_document_id: "collabratec-document-id-2"
|
||||
collabratec_privategroup_id: "collabratec-private-group-id-2"
|
||||
}
|
||||
]
|
||||
|
||||
describe "when update succeeds", ->
|
||||
beforeEach ->
|
||||
@ProjectModel.update = sinon.stub().yields()
|
||||
@ProjectCollabratecDetailsHandler.setCollabratecUsers @projectId, @collabratecUsers, @callback
|
||||
|
||||
it "should update project model", ->
|
||||
update = $set: {
|
||||
collabratecUsers: @collabratecUsers
|
||||
}
|
||||
expect(@ProjectModel.update).to.have.been.calledWith { _id: @projectId }, update, @callback
|
||||
|
||||
describe "when update has error", ->
|
||||
beforeEach ->
|
||||
@ProjectModel.update = sinon.stub().yields("error")
|
||||
@ProjectCollabratecDetailsHandler.setCollabratecUsers @projectId, @collabratecUsers, @callback
|
||||
|
||||
it "should callback with error", ->
|
||||
expect(@callback).to.have.been.calledWith("error")
|
||||
|
||||
describe "with invalid project_id", ->
|
||||
beforeEach ->
|
||||
@ProjectModel.update = sinon.stub()
|
||||
@ProjectCollabratecDetailsHandler.setCollabratecUsers "bad-project-id", @collabratecUsers, @callback
|
||||
|
||||
it "should not update", ->
|
||||
expect(@ProjectModel.update).not.to.have.beenCalled
|
||||
|
||||
it "should callback with error", ->
|
||||
expect(@callback.firstCall.args[0]).to.be.instanceOf Error
|
||||
|
||||
describe "with invalid user_id", ->
|
||||
beforeEach ->
|
||||
@collabratecUsers[1].user_id = "bad-user-id"
|
||||
@ProjectModel.update = sinon.stub()
|
||||
@ProjectCollabratecDetailsHandler.setCollabratecUsers @projectId, @collabratecUsers, @callback
|
||||
|
||||
it "should not update", ->
|
||||
expect(@ProjectModel.update).not.to.have.beenCalled
|
||||
|
||||
it "should callback with error", ->
|
||||
expect(@callback.firstCall.args[0]).to.be.instanceOf Error
|
||||
|
||||
describe "unlinkCollabratecUserProject", ->
|
||||
|
||||
describe "when update succeeds", ->
|
||||
@@ -172,3 +230,43 @@ describe "ProjectCollabratecDetailsHandler", ->
|
||||
|
||||
it "should callback with error", ->
|
||||
expect(@callback.firstCall.args[0]).to.be.instanceOf Error
|
||||
|
||||
describe "updateCollabratecUserIds", ->
|
||||
|
||||
describe "when update succeeds", ->
|
||||
beforeEach ->
|
||||
@ProjectModel.update = sinon.stub().yields()
|
||||
@ProjectCollabratecDetailsHandler.updateCollabratecUserIds @userId, @userId2, @callback
|
||||
|
||||
it "should update project model", ->
|
||||
expect(@ProjectModel.update).to.have.been.calledWith { "collabratecUsers.user_id": @userId }, { $set: "collabratecUsers.$.user_id": @userId2 }, { multi: true}, @callback
|
||||
|
||||
describe "when update has error", ->
|
||||
beforeEach ->
|
||||
@ProjectModel.update = sinon.stub().yields("error")
|
||||
@ProjectCollabratecDetailsHandler.updateCollabratecUserIds @userId, @userId2, @callback
|
||||
|
||||
it "should callback with error", ->
|
||||
expect(@callback).to.have.been.calledWith("error")
|
||||
|
||||
describe "with invalid old_user_id", ->
|
||||
beforeEach ->
|
||||
@ProjectModel.update = sinon.stub()
|
||||
@ProjectCollabratecDetailsHandler.updateCollabratecUserIds "bad-user-id", @userId2, @callback
|
||||
|
||||
it "should not update", ->
|
||||
expect(@ProjectModel.update).not.to.have.beenCalled
|
||||
|
||||
it "should callback with error", ->
|
||||
expect(@callback.firstCall.args[0]).to.be.instanceOf Error
|
||||
|
||||
describe "with invalid new_user_id", ->
|
||||
beforeEach ->
|
||||
@ProjectModel.update = sinon.stub()
|
||||
@ProjectCollabratecDetailsHandler.updateCollabratecUserIds @userId, "bad-user-id", @callback
|
||||
|
||||
it "should not update", ->
|
||||
expect(@ProjectModel.update).not.to.have.beenCalled
|
||||
|
||||
it "should callback with error", ->
|
||||
expect(@callback.firstCall.args[0]).to.be.instanceOf Error
|
||||
@@ -177,3 +177,33 @@ describe "ProjectGetter", ->
|
||||
tokenReadOnly: ['mock-token-ro-projects']
|
||||
})
|
||||
.should.equal true
|
||||
|
||||
describe "getProjectIdByReadAndWriteToken", ->
|
||||
describe "when project find returns project", ->
|
||||
@beforeEach ->
|
||||
@Project.findOne = sinon.stub().yields(null, {_id: "project-id"})
|
||||
@ProjectGetter.getProjectIdByReadAndWriteToken "token", @callback
|
||||
|
||||
it "should find project with token", ->
|
||||
@Project.findOne.calledWithMatch(
|
||||
{'tokens.readAndWrite': "token"}
|
||||
).should.equal true
|
||||
|
||||
it "should callback with project id", ->
|
||||
@callback.calledWith(null, "project-id").should.equal true
|
||||
|
||||
describe "when project not found", ->
|
||||
@beforeEach ->
|
||||
@Project.findOne = sinon.stub().yields()
|
||||
@ProjectGetter.getProjectIdByReadAndWriteToken "token", @callback
|
||||
|
||||
it "should callback empty", ->
|
||||
expect(@callback.firstCall.args.length).to.equal 0
|
||||
|
||||
describe "when project find returns error", ->
|
||||
@beforeEach ->
|
||||
@Project.findOne = sinon.stub().yields("error")
|
||||
@ProjectGetter.getProjectIdByReadAndWriteToken "token", @callback
|
||||
|
||||
it "should callback with error", ->
|
||||
@callback.calledWith("error").should.equal true
|
||||
|
||||
Reference in New Issue
Block a user