RouterTests.js 3.5 KB

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