LabelsTests.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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('mongodb')
  17. const request = require('./helpers/request')
  18. const User = require('./helpers/User')
  19. const MockProjectHistoryApiClass = require('./mocks/MockProjectHistoryApi')
  20. let MockProjectHistoryApi
  21. before(function() {
  22. MockProjectHistoryApi = MockProjectHistoryApiClass.instance()
  23. })
  24. describe('Labels', function() {
  25. beforeEach(function(done) {
  26. this.owner = new User()
  27. return this.owner.login(error => {
  28. if (error != null) {
  29. throw error
  30. }
  31. return this.owner.createProject(
  32. 'example-project',
  33. { template: 'example' },
  34. (error, project_id) => {
  35. this.project_id = project_id
  36. if (error != null) {
  37. throw error
  38. }
  39. return done()
  40. }
  41. )
  42. })
  43. })
  44. it('getting labels', function(done) {
  45. const label_id = new ObjectId().toString()
  46. const comment = 'a label comment'
  47. const version = 3
  48. MockProjectHistoryApi.addLabel(this.project_id, {
  49. id: label_id,
  50. comment,
  51. version
  52. })
  53. return this.owner.request(
  54. {
  55. method: 'GET',
  56. url: `/project/${this.project_id}/labels`,
  57. json: true
  58. },
  59. (error, response, body) => {
  60. if (error != null) {
  61. throw error
  62. }
  63. expect(response.statusCode).to.equal(200)
  64. expect(body).to.deep.equal([{ id: label_id, comment, version }])
  65. return done()
  66. }
  67. )
  68. })
  69. it('creating a label', function(done) {
  70. const comment = 'a label comment'
  71. const version = 3
  72. return this.owner.request(
  73. {
  74. method: 'POST',
  75. url: `/project/${this.project_id}/labels`,
  76. json: { comment, version }
  77. },
  78. (error, response, body) => {
  79. if (error != null) {
  80. throw error
  81. }
  82. expect(response.statusCode).to.equal(200)
  83. const { label_id } = body
  84. expect(MockProjectHistoryApi.getLabels(this.project_id)).to.deep.equal([
  85. { id: label_id, comment, version }
  86. ])
  87. return done()
  88. }
  89. )
  90. })
  91. it('deleting a label', function(done) {
  92. const label_id = new ObjectId().toString()
  93. const comment = 'a label comment'
  94. const version = 3
  95. MockProjectHistoryApi.addLabel(this.project_id, {
  96. id: label_id,
  97. comment,
  98. version
  99. })
  100. return this.owner.request(
  101. {
  102. method: 'DELETE',
  103. url: `/project/${this.project_id}/labels/${label_id}`,
  104. json: true
  105. },
  106. (error, response, body) => {
  107. if (error != null) {
  108. throw error
  109. }
  110. expect(response.statusCode).to.equal(204)
  111. expect(MockProjectHistoryApi.getLabels(this.project_id)).to.deep.equal(
  112. []
  113. )
  114. return done()
  115. }
  116. )
  117. })
  118. })