LabelsTests.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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(function() {
  41. return MockProjectHistoryApi.reset()
  42. })
  43. it('getting labels', function(done) {
  44. const label_id = new ObjectId().toString()
  45. const comment = 'a label comment'
  46. const version = 3
  47. MockProjectHistoryApi.addLabel(this.project_id, {
  48. id: label_id,
  49. comment,
  50. version
  51. })
  52. return this.owner.request(
  53. {
  54. method: 'GET',
  55. url: `/project/${this.project_id}/labels`,
  56. json: true
  57. },
  58. (error, response, body) => {
  59. if (error != null) {
  60. throw error
  61. }
  62. expect(response.statusCode).to.equal(200)
  63. expect(body).to.deep.equal([{ id: label_id, comment, version }])
  64. return done()
  65. }
  66. )
  67. })
  68. it('creating a label', function(done) {
  69. const comment = 'a label comment'
  70. const version = 3
  71. return this.owner.request(
  72. {
  73. method: 'POST',
  74. url: `/project/${this.project_id}/labels`,
  75. json: { comment, version }
  76. },
  77. (error, response, body) => {
  78. if (error != null) {
  79. throw error
  80. }
  81. expect(response.statusCode).to.equal(200)
  82. const { label_id } = body
  83. expect(MockProjectHistoryApi.getLabels(this.project_id)).to.deep.equal([
  84. { id: label_id, comment, version }
  85. ])
  86. return done()
  87. }
  88. )
  89. })
  90. it('deleting a label', function(done) {
  91. const label_id = new ObjectId().toString()
  92. const comment = 'a label comment'
  93. const version = 3
  94. MockProjectHistoryApi.addLabel(this.project_id, {
  95. id: label_id,
  96. comment,
  97. version
  98. })
  99. return this.owner.request(
  100. {
  101. method: 'DELETE',
  102. url: `/project/${this.project_id}/labels/${label_id}`,
  103. json: true
  104. },
  105. (error, response, body) => {
  106. if (error != null) {
  107. throw error
  108. }
  109. expect(response.statusCode).to.equal(204)
  110. expect(MockProjectHistoryApi.getLabels(this.project_id)).to.deep.equal(
  111. []
  112. )
  113. return done()
  114. }
  115. )
  116. })
  117. })