HttpControllerTests.js 3.1 KB

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