2019-05-10 10:17:13 +00:00
|
|
|
/* eslint-env node, mocha */
|
|
|
|
'use strict'
|
|
|
|
|
|
|
|
const assert = require('assert')
|
|
|
|
const mock = require('mock-require')
|
|
|
|
const sinon = require('sinon')
|
2019-05-10 11:10:00 +00:00
|
|
|
const { removeModuleFromRequireCache, makeMockSocket } = require('./utils')
|
2019-05-10 10:17:13 +00:00
|
|
|
|
|
|
|
describe('cleanDanglingUser', function () {
|
|
|
|
let clock
|
|
|
|
beforeEach(() => {
|
|
|
|
clock = sinon.useFakeTimers()
|
|
|
|
mock('../../lib/processQueue', require('../testDoubles/ProcessQueueFake'))
|
|
|
|
mock('../../lib/logger', {
|
|
|
|
error: () => {},
|
|
|
|
info: () => {}
|
|
|
|
})
|
|
|
|
mock('../../lib/history', {})
|
|
|
|
mock('../../lib/models', {
|
|
|
|
Revision: {
|
|
|
|
saveAllNotesRevision: () => {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
mock('../../lib/config', {
|
|
|
|
debug: true
|
|
|
|
})
|
2019-05-10 11:10:00 +00:00
|
|
|
mock('../../lib/realtimeUpdateDirtyNoteJob', require('../testDoubles/realtimeJobStub'))
|
|
|
|
mock('../../lib/realtimeSaveRevisionJob', require('../testDoubles/realtimeJobStub'))
|
2019-05-10 10:17:13 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
clock.restore()
|
|
|
|
removeModuleFromRequireCache('../../lib/realtime')
|
|
|
|
mock.stopAll()
|
|
|
|
sinon.restore()
|
|
|
|
})
|
|
|
|
|
2019-05-10 11:10:00 +00:00
|
|
|
it('should call queueForDisconnectSpy when user is dangling', (done) => {
|
2019-05-10 10:17:13 +00:00
|
|
|
const realtime = require('../../lib/realtime')
|
|
|
|
const queueForDisconnectSpy = sinon.spy(realtime, 'queueForDisconnect')
|
|
|
|
realtime.io = {
|
|
|
|
to: sinon.stub().callsFake(function () {
|
|
|
|
return {
|
|
|
|
emit: sinon.fake()
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
sockets: {
|
|
|
|
connected: {}
|
|
|
|
}
|
|
|
|
}
|
2019-08-04 15:21:00 +00:00
|
|
|
const user1Socket = makeMockSocket()
|
|
|
|
const user2Socket = makeMockSocket()
|
2019-05-10 10:17:13 +00:00
|
|
|
|
|
|
|
user1Socket.rooms.push('room1')
|
|
|
|
|
|
|
|
realtime.io.sockets.connected[user1Socket.id] = user1Socket
|
|
|
|
realtime.io.sockets.connected[user2Socket.id] = user2Socket
|
|
|
|
|
|
|
|
realtime.users[user1Socket.id] = user1Socket
|
|
|
|
realtime.users[user2Socket.id] = user2Socket
|
|
|
|
clock.tick(60000)
|
|
|
|
clock.restore()
|
|
|
|
setTimeout(() => {
|
|
|
|
assert(queueForDisconnectSpy.called)
|
|
|
|
done()
|
|
|
|
}, 50)
|
|
|
|
})
|
|
|
|
})
|