HttpControllerTests.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 request = require('request').defaults({
  14. baseUrl: 'http://localhost:3026',
  15. })
  16. const RealTimeClient = require('./helpers/RealTimeClient')
  17. const FixturesManager = require('./helpers/FixturesManager')
  18. describe('HttpControllerTests', function () {
  19. describe('without a user', function () {
  20. return it('should return 404 for the client view', function (done) {
  21. const client_id = 'not-existing'
  22. return request.get(
  23. {
  24. url: `/clients/${client_id}`,
  25. json: true,
  26. },
  27. (error, response, data) => {
  28. if (error) {
  29. return done(error)
  30. }
  31. expect(response.statusCode).to.equal(404)
  32. return done()
  33. }
  34. )
  35. })
  36. })
  37. return describe('with a user and after joining a project', function () {
  38. before(function (done) {
  39. return async.series(
  40. [
  41. cb => {
  42. return FixturesManager.setUpProject(
  43. {
  44. privilegeLevel: 'owner',
  45. },
  46. (error, { project_id, user_id }) => {
  47. this.project_id = project_id
  48. this.user_id = user_id
  49. return cb(error)
  50. }
  51. )
  52. },
  53. cb => {
  54. return FixturesManager.setUpDoc(
  55. this.project_id,
  56. {},
  57. (error, { doc_id }) => {
  58. this.doc_id = doc_id
  59. return cb(error)
  60. }
  61. )
  62. },
  63. cb => {
  64. this.client = RealTimeClient.connect()
  65. return this.client.on('connectionAccepted', cb)
  66. },
  67. cb => {
  68. return this.client.emit(
  69. 'joinProject',
  70. { project_id: this.project_id },
  71. cb
  72. )
  73. },
  74. cb => {
  75. return this.client.emit('joinDoc', this.doc_id, cb)
  76. },
  77. ],
  78. done
  79. )
  80. })
  81. return it('should send a client view', function (done) {
  82. return request.get(
  83. {
  84. url: `/clients/${this.client.socket.sessionid}`,
  85. json: true,
  86. },
  87. (error, response, data) => {
  88. if (error) {
  89. return done(error)
  90. }
  91. expect(response.statusCode).to.equal(200)
  92. expect(data.connected_time).to.exist
  93. delete data.connected_time
  94. // .email is not set in the session
  95. delete data.email
  96. expect(data).to.deep.equal({
  97. client_id: this.client.socket.sessionid,
  98. first_name: 'Joe',
  99. last_name: 'Bloggs',
  100. project_id: this.project_id,
  101. user_id: this.user_id,
  102. rooms: [this.project_id, this.doc_id],
  103. })
  104. return done()
  105. }
  106. )
  107. })
  108. })
  109. })