LabelsTests.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /* eslint-disable
  2. max-len,
  3. no-unused-vars,
  4. */
  5. // TODO: This file was created by bulk-decaffeinate.
  6. // Fix any style issues and re-enable lint.
  7. /*
  8. * decaffeinate suggestions:
  9. * DS102: Remove unnecessary code created because of implicit returns
  10. * DS207: Consider shorter variations of null checks
  11. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  12. */
  13. const _ = require('lodash')
  14. const { expect } = require('chai')
  15. const { ObjectId } = require('mongodb-legacy')
  16. const User = require('../../../../../test/acceptance/src/helpers/User')
  17. const MockProjectHistoryApiClass = require('../../../../../test/acceptance/src/mocks/MockProjectHistoryApi')
  18. let MockProjectHistoryApi
  19. before(function () {
  20. MockProjectHistoryApi = MockProjectHistoryApiClass.instance()
  21. })
  22. describe('Labels', function () {
  23. beforeEach(function (done) {
  24. this.owner = new User()
  25. return this.owner.login(error => {
  26. if (error != null) {
  27. throw error
  28. }
  29. return this.owner.createProject(
  30. 'example-project',
  31. { template: 'example' },
  32. (error, projectId) => {
  33. this.project_id = projectId
  34. if (error != null) {
  35. throw error
  36. }
  37. return done()
  38. }
  39. )
  40. })
  41. })
  42. it('getting labels', function (done) {
  43. const labelId = new ObjectId().toString()
  44. const comment = 'a label comment'
  45. const version = 3
  46. MockProjectHistoryApi.addLabel(this.project_id, {
  47. id: labelId,
  48. comment,
  49. version,
  50. })
  51. return this.owner.request(
  52. {
  53. method: 'GET',
  54. url: `/project/${this.project_id}/labels`,
  55. json: true,
  56. },
  57. (error, response, body) => {
  58. if (error != null) {
  59. throw error
  60. }
  61. expect(response.statusCode).to.equal(200)
  62. expect(body).to.deep.equal([{ id: labelId, comment, version }])
  63. return done()
  64. }
  65. )
  66. })
  67. it('creating a label', function (done) {
  68. const comment = 'a label comment'
  69. const version = 3
  70. return this.owner.request(
  71. {
  72. method: 'POST',
  73. url: `/project/${this.project_id}/labels`,
  74. json: { comment, version },
  75. },
  76. (error, response, body) => {
  77. if (error != null) {
  78. throw error
  79. }
  80. expect(response.statusCode).to.equal(200)
  81. const { label_id: labelId } = body
  82. expect(MockProjectHistoryApi.getLabels(this.project_id)).to.deep.equal([
  83. { id: labelId, comment, version },
  84. ])
  85. return done()
  86. }
  87. )
  88. })
  89. it('deleting a label', function (done) {
  90. const labelId = new ObjectId().toString()
  91. const comment = 'a label comment'
  92. const version = 3
  93. MockProjectHistoryApi.addLabel(this.project_id, {
  94. id: labelId,
  95. comment,
  96. version,
  97. })
  98. return this.owner.request(
  99. {
  100. method: 'DELETE',
  101. url: `/project/${this.project_id}/labels/${labelId}`,
  102. json: true,
  103. },
  104. (error, response, body) => {
  105. if (error != null) {
  106. throw error
  107. }
  108. expect(response.statusCode).to.equal(204)
  109. expect(MockProjectHistoryApi.getLabels(this.project_id)).to.deep.equal(
  110. []
  111. )
  112. return done()
  113. }
  114. )
  115. })
  116. })