HttpControllerTests.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 {
  10. fetchJson,
  11. fetchNothing,
  12. RequestFailedError,
  13. } from '@overleaf/fetch-utils'
  14. import { expect } from 'chai'
  15. import RealTimeClient from './helpers/RealTimeClient.js'
  16. import FixturesManager from './helpers/FixturesManager.js'
  17. describe('HttpControllerTests', function () {
  18. describe('without a user', function () {
  19. it('should return 404 for the client view', async function () {
  20. const clientId = 'not-existing'
  21. try {
  22. await fetchNothing(`http://127.0.0.1:3026/clients/${clientId}`)
  23. expect.fail('request should have failed')
  24. } catch (error) {
  25. expect(error).to.be.instanceof(RequestFailedError)
  26. expect(error.response.status).to.equal(404)
  27. }
  28. })
  29. })
  30. describe('with a user and after joining a project', function () {
  31. before(function (done) {
  32. async.series(
  33. [
  34. cb => {
  35. FixturesManager.setUpProject(
  36. {
  37. privilegeLevel: 'owner',
  38. },
  39. (error, { project_id: projectId, user_id: userId }) => {
  40. this.project_id = projectId
  41. this.user_id = userId
  42. cb(error)
  43. }
  44. )
  45. },
  46. cb => {
  47. FixturesManager.setUpDoc(
  48. this.project_id,
  49. {},
  50. (error, { doc_id: docId }) => {
  51. this.doc_id = docId
  52. cb(error)
  53. }
  54. )
  55. },
  56. cb => {
  57. this.client = RealTimeClient.connect(this.project_id, cb)
  58. },
  59. cb => {
  60. this.client.emit('joinDoc', this.doc_id, cb)
  61. },
  62. ],
  63. done
  64. )
  65. })
  66. it('should send a client view', async function () {
  67. const data = await fetchJson(
  68. `http://127.0.0.1:3026/clients/${this.client.socket.sessionid}`
  69. )
  70. expect(data.connected_time).to.exist
  71. delete data.connected_time
  72. // .email is not set in the session
  73. delete data.email
  74. expect(data).to.deep.equal({
  75. client_id: this.client.socket.sessionid,
  76. first_name: 'Joe',
  77. last_name: 'Bloggs',
  78. project_id: this.project_id,
  79. user_id: this.user_id,
  80. rooms: [this.project_id, this.doc_id],
  81. })
  82. })
  83. })
  84. })