SharingTests.js 3.3 KB

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