HttpControllerTests.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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://127.0.0.1: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(this.project_id, cb)
  62. },
  63. cb => {
  64. return this.client.emit('joinDoc', this.doc_id, cb)
  65. },
  66. ],
  67. done
  68. )
  69. })
  70. return it('should send a client view', function (done) {
  71. return request.get(
  72. {
  73. url: `/clients/${this.client.socket.sessionid}`,
  74. json: true,
  75. },
  76. (error, response, data) => {
  77. if (error) {
  78. return done(error)
  79. }
  80. expect(response.statusCode).to.equal(200)
  81. expect(data.connected_time).to.exist
  82. delete data.connected_time
  83. // .email is not set in the session
  84. delete data.email
  85. expect(data).to.deep.equal({
  86. client_id: this.client.socket.sessionid,
  87. first_name: 'Joe',
  88. last_name: 'Bloggs',
  89. project_id: this.project_id,
  90. user_id: this.user_id,
  91. rooms: [this.project_id, this.doc_id],
  92. })
  93. return done()
  94. }
  95. )
  96. })
  97. })
  98. })