LabelsTests.mjs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import { expect } from 'chai'
  2. import mongodb from 'mongodb-legacy'
  3. import User from '../../../../../test/acceptance/src/helpers/User.mjs'
  4. import MockProjectHistoryApiClass from '../../../../../test/acceptance/src/mocks/MockProjectHistoryApi.mjs'
  5. const { ObjectId } = mongodb
  6. let MockProjectHistoryApi
  7. before(function () {
  8. MockProjectHistoryApi = MockProjectHistoryApiClass.instance()
  9. })
  10. describe('Labels', function () {
  11. beforeEach(function (done) {
  12. this.owner = new User()
  13. this.owner.login(error => {
  14. if (error) {
  15. throw error
  16. }
  17. this.owner.createProject(
  18. 'example-project',
  19. { template: 'example' },
  20. (error, projectId) => {
  21. this.project_id = projectId
  22. if (error) {
  23. throw error
  24. }
  25. done()
  26. }
  27. )
  28. })
  29. })
  30. it('getting labels', function (done) {
  31. const labelId = new ObjectId().toString()
  32. const comment = 'a label comment'
  33. const version = 3
  34. MockProjectHistoryApi.addLabel(this.project_id, {
  35. id: labelId,
  36. comment,
  37. version,
  38. })
  39. this.owner.request(
  40. {
  41. method: 'GET',
  42. url: `/project/${this.project_id}/labels`,
  43. json: true,
  44. },
  45. (error, response, body) => {
  46. if (error) {
  47. throw error
  48. }
  49. expect(response.statusCode).to.equal(200)
  50. expect(body).to.deep.equal([{ id: labelId, comment, version }])
  51. done()
  52. }
  53. )
  54. })
  55. it('creating a label', function (done) {
  56. const comment = 'a label comment'
  57. const version = 3
  58. this.owner.request(
  59. {
  60. method: 'POST',
  61. url: `/project/${this.project_id}/labels`,
  62. json: { comment, version },
  63. },
  64. (error, response, body) => {
  65. if (error) {
  66. throw error
  67. }
  68. expect(response.statusCode).to.equal(200)
  69. const { label_id: labelId } = body
  70. expect(MockProjectHistoryApi.getLabels(this.project_id)).to.deep.equal([
  71. { id: labelId, comment, version },
  72. ])
  73. done()
  74. }
  75. )
  76. })
  77. it('deleting a label', function (done) {
  78. const labelId = new ObjectId().toString()
  79. const comment = 'a label comment'
  80. const version = 3
  81. MockProjectHistoryApi.addLabel(this.project_id, {
  82. id: labelId,
  83. comment,
  84. version,
  85. })
  86. this.owner.request(
  87. {
  88. method: 'DELETE',
  89. url: `/project/${this.project_id}/labels/${labelId}`,
  90. json: true,
  91. },
  92. (error, response, body) => {
  93. if (error) {
  94. throw error
  95. }
  96. expect(response.statusCode).to.equal(204)
  97. expect(MockProjectHistoryApi.getLabels(this.project_id)).to.deep.equal(
  98. []
  99. )
  100. done()
  101. }
  102. )
  103. })
  104. })