2024-10-14 06:41:11 -04:00
|
|
|
import { expect } from 'chai'
|
|
|
|
import UserHelper from './helpers/User.js'
|
|
|
|
|
|
|
|
const User = UserHelper.promises
|
2019-10-07 08:13:41 -04:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('Sharing', function () {
|
|
|
|
beforeEach(async function () {
|
2019-10-07 08:13:41 -04:00
|
|
|
this.ownerSession = new User()
|
|
|
|
this.collaboratorSession = new User()
|
|
|
|
this.strangerSession = new User()
|
|
|
|
await this.ownerSession.login()
|
|
|
|
await this.collaboratorSession.login()
|
|
|
|
await this.strangerSession.login()
|
|
|
|
this.owner = await this.ownerSession.get()
|
|
|
|
this.collaborator = await this.collaboratorSession.get()
|
|
|
|
this.stranger = await this.strangerSession.get()
|
|
|
|
this.projectId = await this.ownerSession.createProject('Test project')
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('with read-only collaborator', function () {
|
|
|
|
beforeEach(async function () {
|
2019-10-07 08:13:41 -04:00
|
|
|
await this.ownerSession.addUserToProject(
|
|
|
|
this.projectId,
|
|
|
|
this.collaborator,
|
|
|
|
'readOnly'
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('sets the privilege level to read-write', async function () {
|
2019-10-07 08:13:41 -04:00
|
|
|
await this.ownerSession.setCollaboratorInfo(
|
|
|
|
this.projectId,
|
|
|
|
this.collaborator._id,
|
|
|
|
{ privilegeLevel: 'readAndWrite' }
|
|
|
|
)
|
|
|
|
const project = await this.ownerSession.getProject(this.projectId)
|
2022-05-20 07:29:42 -04:00
|
|
|
expect(project.collaberator_refs).to.deep.equal([this.collaborator._id])
|
2019-10-07 08:13:41 -04:00
|
|
|
expect(project.readOnly_refs).to.deep.equal([])
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('treats setting the privilege to read-only as a noop', async function () {
|
2019-10-07 08:13:41 -04:00
|
|
|
await this.ownerSession.setCollaboratorInfo(
|
|
|
|
this.projectId,
|
|
|
|
this.collaborator._id,
|
|
|
|
{ privilegeLevel: 'readOnly' }
|
|
|
|
)
|
|
|
|
const project = await this.ownerSession.getProject(this.projectId)
|
|
|
|
expect(project.collaberator_refs).to.deep.equal([])
|
2022-05-20 07:29:42 -04:00
|
|
|
expect(project.readOnly_refs).to.deep.equal([this.collaborator._id])
|
2019-10-07 08:13:41 -04:00
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('prevents non-owners to set the privilege level', async function () {
|
2019-10-07 08:13:41 -04:00
|
|
|
await expect(
|
|
|
|
this.collaboratorSession.setCollaboratorInfo(
|
|
|
|
this.projectId,
|
|
|
|
this.collaborator._id,
|
|
|
|
{ privilegeLevel: 'readAndWrite' }
|
|
|
|
)
|
2023-08-28 07:58:27 -04:00
|
|
|
).to.be.rejectedWith(/failed: status=403 /)
|
2019-10-07 08:13:41 -04:00
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('validates the privilege level', async function () {
|
2019-10-07 08:13:41 -04:00
|
|
|
await expect(
|
|
|
|
this.collaboratorSession.setCollaboratorInfo(
|
|
|
|
this.projectId,
|
|
|
|
this.collaborator._id,
|
|
|
|
{ privilegeLevel: 'superpowers' }
|
|
|
|
)
|
2023-08-28 07:58:27 -04:00
|
|
|
).to.be.rejectedWith(/failed: status=400 /)
|
2019-10-07 08:13:41 -04:00
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('returns 404 if the user is not already a collaborator', async function () {
|
2019-10-07 08:13:41 -04:00
|
|
|
await expect(
|
|
|
|
this.ownerSession.setCollaboratorInfo(
|
|
|
|
this.projectId,
|
|
|
|
this.stranger._id,
|
|
|
|
{ privilegeLevel: 'readOnly' }
|
|
|
|
)
|
2023-08-28 07:58:27 -04:00
|
|
|
).to.be.rejectedWith(/failed: status=404 /)
|
2019-10-07 08:13:41 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('with read-write collaborator', function () {
|
|
|
|
beforeEach(async function () {
|
2019-10-07 08:13:41 -04:00
|
|
|
await this.ownerSession.addUserToProject(
|
|
|
|
this.projectId,
|
|
|
|
this.collaborator,
|
|
|
|
'readAndWrite'
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('sets the privilege level to read-only', async function () {
|
2019-10-07 08:13:41 -04:00
|
|
|
await this.ownerSession.setCollaboratorInfo(
|
|
|
|
this.projectId,
|
|
|
|
this.collaborator._id,
|
|
|
|
{ privilegeLevel: 'readOnly' }
|
|
|
|
)
|
|
|
|
const project = await this.ownerSession.getProject(this.projectId)
|
|
|
|
expect(project.collaberator_refs).to.deep.equal([])
|
2022-05-20 07:29:42 -04:00
|
|
|
expect(project.readOnly_refs).to.deep.equal([this.collaborator._id])
|
2019-10-07 08:13:41 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|