LabelsTests.js 3.1 KB

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