HttpControllerTests.js 2.8 KB

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