HttpControllerTests.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * decaffeinate suggestions:
  3. * DS102: Remove unnecessary code created because of implicit returns
  4. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  5. */
  6. const async = require('async');
  7. const {
  8. expect
  9. } = 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', () => it('should return 404 for the client view', function(done) {
  17. const client_id = 'not-existing';
  18. return request.get({
  19. url: `/clients/${client_id}`,
  20. json: true
  21. }, function(error, response, data) {
  22. if (error) { return done(error); }
  23. expect(response.statusCode).to.equal(404);
  24. return done();
  25. });
  26. }));
  27. return describe('with a user and after joining a project', function() {
  28. before(function(done) {
  29. return async.series([
  30. cb => {
  31. return FixturesManager.setUpProject({
  32. privilegeLevel: "owner"
  33. }, (error, {project_id, user_id}) => {
  34. this.project_id = project_id;
  35. this.user_id = user_id;
  36. return cb(error);
  37. });
  38. },
  39. cb => {
  40. return FixturesManager.setUpDoc(this.project_id, {}, (error, {doc_id}) => {
  41. this.doc_id = doc_id;
  42. return cb(error);
  43. });
  44. },
  45. cb => {
  46. this.client = RealTimeClient.connect();
  47. return this.client.on("connectionAccepted", cb);
  48. },
  49. cb => {
  50. return this.client.emit("joinProject", {project_id: this.project_id}, cb);
  51. },
  52. cb => {
  53. return this.client.emit("joinDoc", this.doc_id, cb);
  54. }
  55. ], done);
  56. });
  57. return it('should send a client view', function(done) {
  58. return request.get({
  59. url: `/clients/${this.client.socket.sessionid}`,
  60. json: true
  61. }, (error, response, data) => {
  62. if (error) { return done(error); }
  63. expect(response.statusCode).to.equal(200);
  64. expect(data.connected_time).to.exist;
  65. delete data.connected_time;
  66. // .email is not set in the session
  67. delete data.email;
  68. expect(data).to.deep.equal({
  69. client_id: this.client.socket.sessionid,
  70. first_name: 'Joe',
  71. last_name: 'Bloggs',
  72. project_id: this.project_id,
  73. user_id: this.user_id,
  74. rooms: [
  75. this.project_id,
  76. this.doc_id,
  77. ]
  78. });
  79. return done();
  80. });
  81. });
  82. });
  83. });