SharingTests.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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.be.unordered.ids([
  32. this.collaborator._id
  33. ])
  34. expect(project.readOnly_refs).to.deep.equal([])
  35. })
  36. it('treats setting the privilege to read-only as a noop', async function() {
  37. await this.ownerSession.setCollaboratorInfo(
  38. this.projectId,
  39. this.collaborator._id,
  40. { privilegeLevel: 'readOnly' }
  41. )
  42. const project = await this.ownerSession.getProject(this.projectId)
  43. expect(project.collaberator_refs).to.deep.equal([])
  44. expect(project.readOnly_refs).to.be.unordered.ids([this.collaborator._id])
  45. })
  46. it('prevents non-owners to set the privilege level', async function() {
  47. await expect(
  48. this.collaboratorSession.setCollaboratorInfo(
  49. this.projectId,
  50. this.collaborator._id,
  51. { privilegeLevel: 'readAndWrite' }
  52. )
  53. ).to.be.rejectedWith('Unexpected status code: 403')
  54. })
  55. it('validates the privilege level', async function() {
  56. await expect(
  57. this.collaboratorSession.setCollaboratorInfo(
  58. this.projectId,
  59. this.collaborator._id,
  60. { privilegeLevel: 'superpowers' }
  61. )
  62. ).to.be.rejectedWith('Unexpected status code: 400')
  63. })
  64. it('returns 404 if the user is not already a collaborator', async function() {
  65. await expect(
  66. this.ownerSession.setCollaboratorInfo(
  67. this.projectId,
  68. this.stranger._id,
  69. { privilegeLevel: 'readOnly' }
  70. )
  71. ).to.be.rejectedWith('Unexpected status code: 404')
  72. })
  73. })
  74. describe('with read-write collaborator', function() {
  75. beforeEach(async function() {
  76. await this.ownerSession.addUserToProject(
  77. this.projectId,
  78. this.collaborator,
  79. 'readAndWrite'
  80. )
  81. })
  82. it('sets the privilege level to read-only', async function() {
  83. await this.ownerSession.setCollaboratorInfo(
  84. this.projectId,
  85. this.collaborator._id,
  86. { privilegeLevel: 'readOnly' }
  87. )
  88. const project = await this.ownerSession.getProject(this.projectId)
  89. expect(project.collaberator_refs).to.deep.equal([])
  90. expect(project.readOnly_refs).to.be.unordered.ids([this.collaborator._id])
  91. })
  92. })
  93. })