2020-06-23 13:30:34 -04:00
|
|
|
/* eslint-disable
|
|
|
|
no-return-assign,
|
|
|
|
*/
|
|
|
|
// 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:
|
|
|
|
* 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 16:19:31 -04:00
|
|
|
const { expect } = require('chai')
|
2014-11-07 12:38:12 -05:00
|
|
|
|
2020-06-23 13:30:45 -04:00
|
|
|
const RealTimeClient = require('./helpers/RealTimeClient')
|
2014-11-07 12:38:12 -05:00
|
|
|
|
2020-06-23 13:30:45 -04: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 07:04:45 -04:00
|
|
|
user: { _id: this.user_id },
|
2020-06-23 13:30:45 -04:00
|
|
|
},
|
2021-07-13 07:04:45 -04:00
|
|
|
error => {
|
2020-06-23 13:30:45 -04: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 05:58:05 -04:00
|
|
|
|
2020-06-23 13:30:45 -04:00
|
|
|
return it('should appear in the list of connected clients', function (done) {
|
|
|
|
return RealTimeClient.getConnectedClients((error, clients) => {
|
2021-10-27 05:49:18 -04:00
|
|
|
if (error) return done(error)
|
2020-06-23 13:30:45 -04:00
|
|
|
let included = false
|
|
|
|
for (const client of Array.from(clients)) {
|
|
|
|
if (client.client_id === this.client.socket.sessionid) {
|
|
|
|
included = true
|
|
|
|
break
|
|
|
|
}
|
2020-06-23 13:30:29 -04:00
|
|
|
}
|
2020-06-23 13:30:45 -04:00
|
|
|
expect(included).to.equal(true)
|
|
|
|
return done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|