SharingTests.mjs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import { expect } from 'chai'
  2. import UserHelper from './helpers/User.js'
  3. const User = UserHelper.promises
  4. describe('Sharing', function () {
  5. beforeEach(async function () {
  6. this.ownerSession = new User()
  7. this.collaboratorSession = new User()
  8. this.strangerSession = new User()
  9. await this.ownerSession.login()
  10. await this.collaboratorSession.login()
  11. await this.strangerSession.login()
  12. this.owner = await this.ownerSession.get()
  13. this.collaborator = await this.collaboratorSession.get()
  14. this.stranger = await this.strangerSession.get()
  15. this.projectId = await this.ownerSession.createProject('Test project')
  16. })
  17. describe('with read-only collaborator', function () {
  18. beforeEach(async function () {
  19. await this.ownerSession.addUserToProject(
  20. this.projectId,
  21. this.collaborator,
  22. 'readOnly'
  23. )
  24. })
  25. it('sets the privilege level to read-write', async function () {
  26. await this.ownerSession.setCollaboratorInfo(
  27. this.projectId,
  28. this.collaborator._id,
  29. { privilegeLevel: 'readAndWrite' }
  30. )
  31. const project = await this.ownerSession.getProject(this.projectId)
  32. expect(project.collaberator_refs).to.deep.equal([this.collaborator._id])
  33. expect(project.readOnly_refs).to.deep.equal([])
  34. })
  35. it('treats setting the privilege to read-only as a noop', async function () {
  36. await this.ownerSession.setCollaboratorInfo(
  37. this.projectId,
  38. this.collaborator._id,
  39. { privilegeLevel: 'readOnly' }
  40. )
  41. const project = await this.ownerSession.getProject(this.projectId)
  42. expect(project.collaberator_refs).to.deep.equal([])
  43. expect(project.readOnly_refs).to.deep.equal([this.collaborator._id])
  44. })
  45. it('prevents non-owners to set the privilege level', async function () {
  46. await expect(
  47. this.collaboratorSession.setCollaboratorInfo(
  48. this.projectId,
  49. this.collaborator._id,
  50. { privilegeLevel: 'readAndWrite' }
  51. )
  52. ).to.be.rejectedWith(/failed: status=403 /)
  53. })
  54. it('validates the privilege level', async function () {
  55. await expect(
  56. this.collaboratorSession.setCollaboratorInfo(
  57. this.projectId,
  58. this.collaborator._id,
  59. { privilegeLevel: 'superpowers' }
  60. )
  61. ).to.be.rejectedWith(/failed: status=400 /)
  62. })
  63. it('returns 404 if the user is not already a collaborator', async function () {
  64. await expect(
  65. this.ownerSession.setCollaboratorInfo(
  66. this.projectId,
  67. this.stranger._id,
  68. { privilegeLevel: 'readOnly' }
  69. )
  70. ).to.be.rejectedWith(/failed: status=404 /)
  71. })
  72. })
  73. describe('with read-write collaborator', function () {
  74. beforeEach(async function () {
  75. await this.ownerSession.addUserToProject(
  76. this.projectId,
  77. this.collaborator,
  78. 'readAndWrite'
  79. )
  80. })
  81. it('sets the privilege level to read-only', async function () {
  82. await this.ownerSession.setCollaboratorInfo(
  83. this.projectId,
  84. this.collaborator._id,
  85. { privilegeLevel: 'readOnly' }
  86. )
  87. const project = await this.ownerSession.getProject(this.projectId)
  88. expect(project.collaberator_refs).to.deep.equal([])
  89. expect(project.readOnly_refs).to.deep.equal([this.collaborator._id])
  90. })
  91. })
  92. })