|
|
@@ -640,33 +640,86 @@ describe('CollaboratorsHandler', function () {
|
|
|
)
|
|
|
})
|
|
|
|
|
|
- it('sets a collaborator to reviewer', async function () {
|
|
|
- this.ProjectMock.expects('updateOne')
|
|
|
- .withArgs(
|
|
|
- {
|
|
|
- _id: this.projectId,
|
|
|
- $or: [
|
|
|
- { collaberator_refs: this.userId },
|
|
|
- { readOnly_refs: this.userId },
|
|
|
- { reviewer_refs: this.userId },
|
|
|
- ],
|
|
|
+ describe('sets a collaborator to reviewer when track changes is enabled for everyone', function () {
|
|
|
+ beforeEach(function () {
|
|
|
+ this.ProjectGetter.promises.getProject = sinon.stub().resolves({
|
|
|
+ _id: new ObjectId(),
|
|
|
+ owner_ref: this.addingUserId,
|
|
|
+ name: 'Foo',
|
|
|
+ track_changes: true,
|
|
|
+ })
|
|
|
+ })
|
|
|
+ it('should correctly update the project', async function () {
|
|
|
+ this.ProjectMock.expects('updateOne')
|
|
|
+ .withArgs(
|
|
|
+ {
|
|
|
+ _id: this.projectId,
|
|
|
+ $or: [
|
|
|
+ { collaberator_refs: this.userId },
|
|
|
+ { readOnly_refs: this.userId },
|
|
|
+ { reviewer_refs: this.userId },
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ {
|
|
|
+ $addToSet: { reviewer_refs: this.userId },
|
|
|
+ $set: { track_changes: { [this.userId]: true } },
|
|
|
+ $pull: {
|
|
|
+ readOnly_refs: this.userId,
|
|
|
+ collaberator_refs: this.userId,
|
|
|
+ pendingEditor_refs: this.userId,
|
|
|
+ },
|
|
|
+ }
|
|
|
+ )
|
|
|
+ .chain('exec')
|
|
|
+ .resolves({ matchedCount: 1 })
|
|
|
+ await this.CollaboratorsHandler.promises.setCollaboratorPrivilegeLevel(
|
|
|
+ this.projectId,
|
|
|
+ this.userId,
|
|
|
+ 'review'
|
|
|
+ )
|
|
|
+ })
|
|
|
+ })
|
|
|
+
|
|
|
+ describe('sets a collaborator to reviewer when track changes is not enabled for everyone', function () {
|
|
|
+ beforeEach(function () {
|
|
|
+ this.ProjectGetter.promises.getProject = sinon.stub().resolves({
|
|
|
+ _id: new ObjectId(),
|
|
|
+ owner_ref: this.addingUserId,
|
|
|
+ name: 'Foo',
|
|
|
+ track_changes: {
|
|
|
+ [this.userId]: true,
|
|
|
},
|
|
|
- {
|
|
|
- $addToSet: { reviewer_refs: this.userId },
|
|
|
- $pull: {
|
|
|
- readOnly_refs: this.userId,
|
|
|
- collaberator_refs: this.userId,
|
|
|
- pendingEditor_refs: this.userId,
|
|
|
+ })
|
|
|
+ })
|
|
|
+ it('should correctly update the project', async function () {
|
|
|
+ this.ProjectMock.expects('updateOne')
|
|
|
+ .withArgs(
|
|
|
+ {
|
|
|
+ _id: this.projectId,
|
|
|
+ $or: [
|
|
|
+ { collaberator_refs: this.userId },
|
|
|
+ { readOnly_refs: this.userId },
|
|
|
+ { reviewer_refs: this.userId },
|
|
|
+ ],
|
|
|
},
|
|
|
- }
|
|
|
+ {
|
|
|
+ $addToSet: { reviewer_refs: this.userId },
|
|
|
+ $set: { [`track_changes.${this.userId}`]: true },
|
|
|
+ $pull: {
|
|
|
+ readOnly_refs: this.userId,
|
|
|
+ collaberator_refs: this.userId,
|
|
|
+ pendingEditor_refs: this.userId,
|
|
|
+ },
|
|
|
+ }
|
|
|
+ )
|
|
|
+ .chain('exec')
|
|
|
+ .resolves({ matchedCount: 1 })
|
|
|
+ await this.CollaboratorsHandler.promises.setCollaboratorPrivilegeLevel(
|
|
|
+ this.projectId,
|
|
|
+ this.userId,
|
|
|
+ 'review'
|
|
|
)
|
|
|
- .chain('exec')
|
|
|
- .resolves({ matchedCount: 1 })
|
|
|
- await this.CollaboratorsHandler.promises.setCollaboratorPrivilegeLevel(
|
|
|
- this.projectId,
|
|
|
- this.userId,
|
|
|
- 'review'
|
|
|
- )
|
|
|
+ })
|
|
|
})
|
|
|
|
|
|
it('sets a collaborator to read-only as a pendingEditor', async function () {
|