2020-06-23 13:30:34 -04:00
|
|
|
// 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
|
|
|
|
*/
|
2020-06-23 13:30:45 -04:00
|
|
|
const async = require('async')
|
|
|
|
const { expect } = require('chai')
|
2020-06-23 13:30:29 -04:00
|
|
|
const request = require('request').defaults({
|
2024-04-25 08:56:00 -04:00
|
|
|
baseUrl: 'http://127.0.0.1:3026',
|
2020-06-23 13:30:45 -04:00
|
|
|
})
|
2020-02-24 06:07:06 -05:00
|
|
|
|
2020-06-23 13:30:45 -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:45 -04:00
|
|
|
describe('HttpControllerTests', function () {
|
|
|
|
describe('without a user', function () {
|
|
|
|
return it('should return 404 for the client view', function (done) {
|
2023-03-20 10:10:40 -04:00
|
|
|
const clientId = 'not-existing'
|
2020-06-23 13:30:45 -04:00
|
|
|
return request.get(
|
|
|
|
{
|
2023-03-20 10:10:40 -04:00
|
|
|
url: `/clients/${clientId}`,
|
2021-07-13 07:04:45 -04:00
|
|
|
json: true,
|
2020-06-23 13:30:45 -04:00
|
|
|
},
|
|
|
|
(error, response, data) => {
|
|
|
|
if (error) {
|
|
|
|
return done(error)
|
|
|
|
}
|
|
|
|
expect(response.statusCode).to.equal(404)
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
2020-02-24 06:07:06 -05:00
|
|
|
|
2020-06-23 13:30:45 -04:00
|
|
|
return describe('with a user and after joining a project', function () {
|
|
|
|
before(function (done) {
|
|
|
|
return async.series(
|
|
|
|
[
|
2021-07-13 07:04:45 -04:00
|
|
|
cb => {
|
2020-06-23 13:30:45 -04:00
|
|
|
return FixturesManager.setUpProject(
|
|
|
|
{
|
2021-07-13 07:04:45 -04:00
|
|
|
privilegeLevel: 'owner',
|
2020-06-23 13:30:45 -04:00
|
|
|
},
|
2023-03-20 10:10:40 -04:00
|
|
|
(error, { project_id: projectId, user_id: userId }) => {
|
|
|
|
this.project_id = projectId
|
|
|
|
this.user_id = userId
|
2020-06-23 13:30:45 -04:00
|
|
|
return cb(error)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
},
|
2020-02-24 06:07:06 -05:00
|
|
|
|
2021-07-13 07:04:45 -04:00
|
|
|
cb => {
|
2020-06-23 13:30:45 -04:00
|
|
|
return FixturesManager.setUpDoc(
|
|
|
|
this.project_id,
|
|
|
|
{},
|
2023-03-20 10:10:40 -04:00
|
|
|
(error, { doc_id: docId }) => {
|
|
|
|
this.doc_id = docId
|
2020-06-23 13:30:45 -04:00
|
|
|
return cb(error)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
},
|
2020-02-24 06:07:06 -05:00
|
|
|
|
2021-07-13 07:04:45 -04:00
|
|
|
cb => {
|
2023-11-29 09:50:21 -05:00
|
|
|
this.client = RealTimeClient.connect(this.project_id, cb)
|
2020-06-23 13:30:45 -04:00
|
|
|
},
|
2020-02-24 06:07:06 -05:00
|
|
|
|
2021-07-13 07:04:45 -04:00
|
|
|
cb => {
|
2020-06-23 13:30:45 -04:00
|
|
|
return this.client.emit('joinDoc', this.doc_id, cb)
|
2021-07-13 07:04:45 -04:00
|
|
|
},
|
2020-06-23 13:30:45 -04:00
|
|
|
],
|
|
|
|
done
|
|
|
|
)
|
|
|
|
})
|
2020-02-24 06:07:06 -05:00
|
|
|
|
2020-06-23 13:30:45 -04:00
|
|
|
return it('should send a client view', function (done) {
|
|
|
|
return request.get(
|
|
|
|
{
|
|
|
|
url: `/clients/${this.client.socket.sessionid}`,
|
2021-07-13 07:04:45 -04:00
|
|
|
json: true,
|
2020-06-23 13:30:45 -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
|
|
|
|
expect(data).to.deep.equal({
|
|
|
|
client_id: this.client.socket.sessionid,
|
|
|
|
first_name: 'Joe',
|
|
|
|
last_name: 'Bloggs',
|
|
|
|
project_id: this.project_id,
|
|
|
|
user_id: this.user_id,
|
2021-07-13 07:04:45 -04:00
|
|
|
rooms: [this.project_id, this.doc_id],
|
2020-06-23 13:30:45 -04:00
|
|
|
})
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|