ProjectOwnershipTransferTests.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. const { expect } = require('chai')
  2. const User = require('./helpers/User').promises
  3. describe('Project ownership transfer', function () {
  4. beforeEach(async function () {
  5. this.ownerSession = new User()
  6. this.collaboratorSession = new User()
  7. this.strangerSession = new User()
  8. this.adminSession = new User()
  9. await this.adminSession.ensureUserExists()
  10. await this.adminSession.ensureAdmin()
  11. await this.ownerSession.login()
  12. await this.collaboratorSession.login()
  13. await this.strangerSession.login()
  14. await this.adminSession.login()
  15. this.owner = await this.ownerSession.get()
  16. this.collaborator = await this.collaboratorSession.get()
  17. this.stranger = await this.strangerSession.get()
  18. this.admin = await this.adminSession.get()
  19. this.projectId = await this.ownerSession.createProject('Test project')
  20. await this.ownerSession.addUserToProject(
  21. this.projectId,
  22. this.collaborator,
  23. 'readAndWrite'
  24. )
  25. })
  26. describe('happy path', function () {
  27. beforeEach(async function () {
  28. await this.ownerSession.transferProjectOwnership(
  29. this.projectId,
  30. this.collaborator._id
  31. )
  32. })
  33. it('changes the project owner', async function () {
  34. const project = await this.collaboratorSession.getProject(this.projectId)
  35. expect(project.owner_ref.toString()).to.equal(
  36. this.collaborator._id.toString()
  37. )
  38. })
  39. it('adds the previous owner as a read/write collaborator', async function () {
  40. const project = await this.collaboratorSession.getProject(this.projectId)
  41. expect(project.collaberator_refs.map(x => x.toString())).to.have.members([
  42. this.owner._id.toString(),
  43. ])
  44. })
  45. it('lets the new owner open the project', async function () {
  46. await this.collaboratorSession.openProject(this.projectId)
  47. })
  48. it('lets the previous owner open the project', async function () {
  49. await this.ownerSession.openProject(this.projectId)
  50. })
  51. })
  52. describe('validation', function () {
  53. it('lets only the project owner transfer ownership', async function () {
  54. await expect(
  55. this.collaboratorSession.transferProjectOwnership(
  56. this.projectId,
  57. this.collaborator._id
  58. )
  59. ).to.be.rejectedWith('Unexpected status code: 403')
  60. })
  61. it('prevents transfers to a non-collaborator', async function () {
  62. await expect(
  63. this.ownerSession.transferProjectOwnership(
  64. this.projectId,
  65. this.stranger._id
  66. )
  67. ).to.be.rejectedWith('Unexpected status code: 403')
  68. })
  69. it('allows an admin to transfer to any project to a non-collaborator', async function () {
  70. await expect(
  71. this.adminSession.transferProjectOwnership(
  72. this.projectId,
  73. this.stranger._id
  74. )
  75. ).to.be.fulfilled
  76. })
  77. })
  78. })