2019-09-30 10:46:15 -04:00
|
|
|
const { expect } = require('chai')
|
|
|
|
const User = require('./helpers/User').promises
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('Project ownership transfer', function () {
|
|
|
|
beforeEach(async function () {
|
2019-09-30 10:46:15 -04:00
|
|
|
this.ownerSession = new User()
|
|
|
|
this.collaboratorSession = new User()
|
|
|
|
this.strangerSession = new User()
|
|
|
|
this.adminSession = new User()
|
2023-05-15 09:55:15 -04:00
|
|
|
this.invitedAdminSession = new User()
|
|
|
|
await this.invitedAdminSession.ensureUserExists()
|
|
|
|
await this.invitedAdminSession.ensureAdmin()
|
|
|
|
await this.invitedAdminSession.login()
|
2019-09-30 10:46:15 -04:00
|
|
|
await this.adminSession.ensureUserExists()
|
|
|
|
await this.adminSession.ensureAdmin()
|
|
|
|
await this.ownerSession.login()
|
|
|
|
await this.collaboratorSession.login()
|
|
|
|
await this.strangerSession.login()
|
|
|
|
await this.adminSession.login()
|
|
|
|
this.owner = await this.ownerSession.get()
|
|
|
|
this.collaborator = await this.collaboratorSession.get()
|
|
|
|
this.stranger = await this.strangerSession.get()
|
|
|
|
this.admin = await this.adminSession.get()
|
2023-05-15 09:55:15 -04:00
|
|
|
this.invitedAdmin = await this.invitedAdminSession.get()
|
2019-09-30 10:46:15 -04:00
|
|
|
this.projectId = await this.ownerSession.createProject('Test project')
|
2023-05-15 09:55:15 -04:00
|
|
|
await this.ownerSession.addUserToProject(
|
|
|
|
this.projectId,
|
|
|
|
this.invitedAdmin,
|
|
|
|
'readAndWrite'
|
|
|
|
)
|
2019-09-30 10:46:15 -04:00
|
|
|
await this.ownerSession.addUserToProject(
|
|
|
|
this.projectId,
|
|
|
|
this.collaborator,
|
|
|
|
'readAndWrite'
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('happy path', function () {
|
|
|
|
beforeEach(async function () {
|
2019-09-30 10:46:15 -04:00
|
|
|
await this.ownerSession.transferProjectOwnership(
|
|
|
|
this.projectId,
|
|
|
|
this.collaborator._id
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('changes the project owner', async function () {
|
2019-09-30 10:46:15 -04:00
|
|
|
const project = await this.collaboratorSession.getProject(this.projectId)
|
|
|
|
expect(project.owner_ref.toString()).to.equal(
|
|
|
|
this.collaborator._id.toString()
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('adds the previous owner as a read/write collaborator', async function () {
|
2019-09-30 10:46:15 -04:00
|
|
|
const project = await this.collaboratorSession.getProject(this.projectId)
|
|
|
|
expect(project.collaberator_refs.map(x => x.toString())).to.have.members([
|
2021-04-27 03:52:58 -04:00
|
|
|
this.owner._id.toString(),
|
2023-05-15 09:55:15 -04:00
|
|
|
this.invitedAdmin._id.toString(),
|
2019-09-30 10:46:15 -04:00
|
|
|
])
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('lets the new owner open the project', async function () {
|
2019-09-30 10:46:15 -04:00
|
|
|
await this.collaboratorSession.openProject(this.projectId)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('lets the previous owner open the project', async function () {
|
2019-09-30 10:46:15 -04:00
|
|
|
await this.ownerSession.openProject(this.projectId)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2023-05-15 09:55:15 -04:00
|
|
|
describe('ownership change as admin', function () {
|
|
|
|
it('lets the invited admin transfer ownership', async function () {
|
|
|
|
await this.invitedAdminSession.transferProjectOwnership(
|
|
|
|
this.projectId,
|
|
|
|
this.collaborator._id
|
|
|
|
)
|
|
|
|
const project = await this.invitedAdminSession.getProject(this.projectId)
|
|
|
|
expect(project.owner_ref.toString()).to.equal(
|
|
|
|
this.collaborator._id.toString()
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('lets the non-invited admin transfer ownership', async function () {
|
|
|
|
await this.adminSession.transferProjectOwnership(
|
|
|
|
this.projectId,
|
|
|
|
this.collaborator._id
|
|
|
|
)
|
|
|
|
const project = await this.adminSession.getProject(this.projectId)
|
|
|
|
expect(project.owner_ref.toString()).to.equal(
|
|
|
|
this.collaborator._id.toString()
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('validation', function () {
|
|
|
|
it('lets only the project owner transfer ownership', async function () {
|
2019-09-30 10:46:15 -04:00
|
|
|
await expect(
|
|
|
|
this.collaboratorSession.transferProjectOwnership(
|
|
|
|
this.projectId,
|
|
|
|
this.collaborator._id
|
|
|
|
)
|
2023-08-28 07:58:27 -04:00
|
|
|
).to.be.rejectedWith(/failed: status=403 /)
|
2019-09-30 10:46:15 -04:00
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('prevents transfers to a non-collaborator', async function () {
|
2019-09-30 10:46:15 -04:00
|
|
|
await expect(
|
|
|
|
this.ownerSession.transferProjectOwnership(
|
|
|
|
this.projectId,
|
|
|
|
this.stranger._id
|
|
|
|
)
|
2023-08-28 07:58:27 -04:00
|
|
|
).to.be.rejectedWith(/failed: status=403 /)
|
2019-09-30 10:46:15 -04:00
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('allows an admin to transfer to any project to a non-collaborator', async function () {
|
2019-09-30 10:46:15 -04:00
|
|
|
await expect(
|
|
|
|
this.adminSession.transferProjectOwnership(
|
|
|
|
this.projectId,
|
|
|
|
this.stranger._id
|
|
|
|
)
|
|
|
|
).to.be.fulfilled
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|