RouterTests.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /* eslint-disable
  2. camelcase,
  3. */
  4. // TODO: This file was created by bulk-decaffeinate.
  5. // Fix any style issues and re-enable lint.
  6. /*
  7. * decaffeinate suggestions:
  8. * DS102: Remove unnecessary code created because of implicit returns
  9. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  10. */
  11. const async = require('async')
  12. const { expect } = require('chai')
  13. const RealTimeClient = require('./helpers/RealTimeClient')
  14. const FixturesManager = require('./helpers/FixturesManager')
  15. describe('Router', function () {
  16. return describe('joinProject', function () {
  17. describe('when there is no callback provided', function () {
  18. after(function () {
  19. return process.removeListener('unhandledRejection', this.onUnhandled)
  20. })
  21. before(function (done) {
  22. this.onUnhandled = error => done(error)
  23. process.on('unhandledRejection', this.onUnhandled)
  24. return async.series(
  25. [
  26. cb => {
  27. return FixturesManager.setUpProject(
  28. {
  29. privilegeLevel: 'owner',
  30. project: {
  31. name: 'Test Project',
  32. },
  33. },
  34. (e, { project_id, user_id }) => {
  35. this.project_id = project_id
  36. this.user_id = user_id
  37. return cb(e)
  38. }
  39. )
  40. },
  41. cb => {
  42. this.client = RealTimeClient.connect()
  43. return this.client.on('connectionAccepted', cb)
  44. },
  45. cb => {
  46. this.client = RealTimeClient.connect()
  47. return this.client.on('connectionAccepted', cb)
  48. },
  49. cb => {
  50. this.client.emit('joinProject', { project_id: this.project_id })
  51. return setTimeout(cb, 100)
  52. },
  53. ],
  54. done
  55. )
  56. })
  57. return it('should keep on going', function () {
  58. return expect('still running').to.exist
  59. })
  60. })
  61. return describe('when there are too many arguments', function () {
  62. after(function () {
  63. return process.removeListener('unhandledRejection', this.onUnhandled)
  64. })
  65. before(function (done) {
  66. this.onUnhandled = error => done(error)
  67. process.on('unhandledRejection', this.onUnhandled)
  68. return async.series(
  69. [
  70. cb => {
  71. return FixturesManager.setUpProject(
  72. {
  73. privilegeLevel: 'owner',
  74. project: {
  75. name: 'Test Project',
  76. },
  77. },
  78. (e, { project_id, user_id }) => {
  79. this.project_id = project_id
  80. this.user_id = user_id
  81. return cb(e)
  82. }
  83. )
  84. },
  85. cb => {
  86. this.client = RealTimeClient.connect()
  87. return this.client.on('connectionAccepted', cb)
  88. },
  89. cb => {
  90. this.client = RealTimeClient.connect()
  91. return this.client.on('connectionAccepted', cb)
  92. },
  93. cb => {
  94. return this.client.emit('joinProject', 1, 2, 3, 4, 5, error => {
  95. this.error = error
  96. return cb()
  97. })
  98. },
  99. ],
  100. done
  101. )
  102. })
  103. return it('should return an error message', function () {
  104. return expect(this.error.message).to.equal('unexpected arguments')
  105. })
  106. })
  107. })
  108. })