2020-06-23 13:30:34 -04:00
|
|
|
/* eslint-disable
|
|
|
|
camelcase,
|
|
|
|
*/
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
2020-06-23 13:30:29 -04:00
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
|
|
|
const async = require('async');
|
|
|
|
const {
|
|
|
|
expect
|
|
|
|
} = require('chai');
|
|
|
|
const request = require('request').defaults({
|
2020-02-24 06:07:06 -05:00
|
|
|
baseUrl: 'http://localhost:3026'
|
2020-06-23 13:30:29 -04:00
|
|
|
});
|
2020-02-24 06:07:06 -05:00
|
|
|
|
2020-06-23 13:30:29 -04:00
|
|
|
const RealTimeClient = require("./helpers/RealTimeClient");
|
|
|
|
const FixturesManager = require("./helpers/FixturesManager");
|
2020-02-24 06:07:06 -05:00
|
|
|
|
2020-06-23 13:30:29 -04:00
|
|
|
describe('HttpControllerTests', function() {
|
2020-06-23 13:30:34 -04:00
|
|
|
describe('without a user', function() { return it('should return 404 for the client view', function(done) {
|
2020-06-23 13:30:29 -04:00
|
|
|
const client_id = 'not-existing';
|
|
|
|
return request.get({
|
|
|
|
url: `/clients/${client_id}`,
|
|
|
|
json: true
|
2020-06-23 13:30:34 -04:00
|
|
|
}, (error, response, data) => {
|
2020-06-23 13:30:29 -04:00
|
|
|
if (error) { return done(error); }
|
|
|
|
expect(response.statusCode).to.equal(404);
|
|
|
|
return done();
|
|
|
|
});
|
2020-06-23 13:30:34 -04:00
|
|
|
}); });
|
2020-02-24 06:07:06 -05:00
|
|
|
|
2020-06-23 13:30:29 -04:00
|
|
|
return describe('with a user and after joining a project', function() {
|
|
|
|
before(function(done) {
|
|
|
|
return async.series([
|
|
|
|
cb => {
|
|
|
|
return FixturesManager.setUpProject({
|
2020-02-24 06:07:06 -05:00
|
|
|
privilegeLevel: "owner"
|
2020-06-23 13:30:29 -04:00
|
|
|
}, (error, {project_id, user_id}) => {
|
|
|
|
this.project_id = project_id;
|
|
|
|
this.user_id = user_id;
|
|
|
|
return cb(error);
|
|
|
|
});
|
|
|
|
},
|
2020-02-24 06:07:06 -05:00
|
|
|
|
2020-06-23 13:30:29 -04:00
|
|
|
cb => {
|
|
|
|
return FixturesManager.setUpDoc(this.project_id, {}, (error, {doc_id}) => {
|
|
|
|
this.doc_id = doc_id;
|
|
|
|
return cb(error);
|
|
|
|
});
|
|
|
|
},
|
2020-02-24 06:07:06 -05:00
|
|
|
|
2020-06-23 13:30:29 -04:00
|
|
|
cb => {
|
|
|
|
this.client = RealTimeClient.connect();
|
|
|
|
return this.client.on("connectionAccepted", cb);
|
|
|
|
},
|
2020-02-24 06:07:06 -05:00
|
|
|
|
2020-06-23 13:30:29 -04:00
|
|
|
cb => {
|
|
|
|
return this.client.emit("joinProject", {project_id: this.project_id}, cb);
|
|
|
|
},
|
2020-02-24 06:07:06 -05:00
|
|
|
|
2020-06-23 13:30:29 -04:00
|
|
|
cb => {
|
|
|
|
return this.client.emit("joinDoc", this.doc_id, cb);
|
|
|
|
}
|
|
|
|
], done);
|
|
|
|
});
|
2020-02-24 06:07:06 -05:00
|
|
|
|
2020-06-23 13:30:29 -04:00
|
|
|
return it('should send a client view', function(done) {
|
|
|
|
return request.get({
|
|
|
|
url: `/clients/${this.client.socket.sessionid}`,
|
2020-02-24 06:07:06 -05:00
|
|
|
json: true
|
2020-06-23 13:30:29 -04:00
|
|
|
}, (error, response, data) => {
|
|
|
|
if (error) { return done(error); }
|
|
|
|
expect(response.statusCode).to.equal(200);
|
|
|
|
expect(data.connected_time).to.exist;
|
|
|
|
delete data.connected_time;
|
|
|
|
// .email is not set in the session
|
|
|
|
delete data.email;
|
2020-02-24 06:07:06 -05:00
|
|
|
expect(data).to.deep.equal({
|
2020-06-23 13:30:29 -04:00
|
|
|
client_id: this.client.socket.sessionid,
|
2020-02-24 06:07:06 -05:00
|
|
|
first_name: 'Joe',
|
|
|
|
last_name: 'Bloggs',
|
2020-06-23 13:30:29 -04:00
|
|
|
project_id: this.project_id,
|
|
|
|
user_id: this.user_id,
|
2020-02-24 06:07:06 -05:00
|
|
|
rooms: [
|
2020-06-23 13:30:29 -04:00
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
2020-02-24 06:07:06 -05:00
|
|
|
]
|
2020-06-23 13:30:29 -04:00
|
|
|
});
|
|
|
|
return done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|