2020-06-23 17:30:34 +00:00
|
|
|
/* eslint-disable
|
|
|
|
handle-callback-err,
|
|
|
|
no-return-assign,
|
|
|
|
*/
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
2020-06-23 17:30:29 +00:00
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS101: Remove unnecessary use of Array.from
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* DS207: Consider shorter variations of null checks
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
2021-03-18 20:19:31 +00:00
|
|
|
const { expect } = require('chai')
|
2014-11-07 17:38:12 +00:00
|
|
|
|
2020-06-23 17:30:45 +00:00
|
|
|
const RealTimeClient = require('./helpers/RealTimeClient')
|
2014-11-07 17:38:12 +00:00
|
|
|
|
2020-06-23 17:30:45 +00:00
|
|
|
describe('Session', function () {
|
|
|
|
return describe('with an established session', function () {
|
|
|
|
before(function (done) {
|
|
|
|
this.user_id = 'mock-user-id'
|
|
|
|
RealTimeClient.setSession(
|
|
|
|
{
|
2021-07-13 11:04:45 +00:00
|
|
|
user: { _id: this.user_id },
|
2020-06-23 17:30:45 +00:00
|
|
|
},
|
2021-07-13 11:04:45 +00:00
|
|
|
error => {
|
2020-06-23 17:30:45 +00:00
|
|
|
if (error != null) {
|
|
|
|
throw error
|
|
|
|
}
|
|
|
|
this.client = RealTimeClient.connect()
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
return null
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should not get disconnected', function (done) {
|
|
|
|
let disconnected = false
|
|
|
|
this.client.on('disconnect', () => (disconnected = true))
|
|
|
|
return setTimeout(() => {
|
|
|
|
expect(disconnected).to.equal(false)
|
|
|
|
return done()
|
|
|
|
}, 500)
|
|
|
|
})
|
2019-05-30 09:58:05 +00:00
|
|
|
|
2020-06-23 17:30:45 +00:00
|
|
|
return it('should appear in the list of connected clients', function (done) {
|
|
|
|
return RealTimeClient.getConnectedClients((error, clients) => {
|
|
|
|
let included = false
|
|
|
|
for (const client of Array.from(clients)) {
|
|
|
|
if (client.client_id === this.client.socket.sessionid) {
|
|
|
|
included = true
|
|
|
|
break
|
|
|
|
}
|
2020-06-23 17:30:29 +00:00
|
|
|
}
|
2020-06-23 17:30:45 +00:00
|
|
|
expect(included).to.equal(true)
|
|
|
|
return done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|