HttpControllerTests.js 2.6 KB

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