mirror of
https://github.com/status-im/codimd.git
synced 2025-02-11 08:06:42 +00:00
test: fix test case
Signed-off-by: Raccoon <raccoon@hackmd.io>
This commit is contained in:
parent
638a8872c8
commit
ff90fd0fe1
@ -4,26 +4,24 @@
|
||||
const assert = require('assert')
|
||||
const mock = require('mock-require')
|
||||
const sinon = require('sinon')
|
||||
const { createFakeLogger } = require('../testDoubles/loggerFake')
|
||||
const { removeModuleFromRequireCache, makeMockSocket } = require('./utils')
|
||||
|
||||
describe('cleanDanglingUser', function () {
|
||||
let clock
|
||||
beforeEach(() => {
|
||||
clock = sinon.useFakeTimers()
|
||||
mock('../../dist/models', {})
|
||||
mock('../../dist/processQueue', require('../testDoubles/ProcessQueueFake'))
|
||||
mock('../../dist/logger', {
|
||||
error: () => {},
|
||||
info: () => {}
|
||||
})
|
||||
mock('../../dist/logger', createFakeLogger())
|
||||
mock('../../dist/history', {})
|
||||
mock('../../dist/models', {
|
||||
Revision: {
|
||||
saveAllNotesRevision: () => {
|
||||
}
|
||||
mock('../../dist/services/note', {
|
||||
saveAllNotesRevision: () => {
|
||||
}
|
||||
})
|
||||
mock('../../dist/config', {
|
||||
debug: true
|
||||
debug: true,
|
||||
db: {}
|
||||
})
|
||||
mock('../../dist/realtimeUpdateDirtyNoteJob', require('../testDoubles/realtimeJobStub'))
|
||||
mock('../../dist/realtimeSaveRevisionJob', require('../testDoubles/realtimeJobStub'))
|
||||
|
@ -4,6 +4,7 @@
|
||||
const assert = require('assert')
|
||||
const mock = require('mock-require')
|
||||
const sinon = require('sinon')
|
||||
const { createFakeLogger } = require('../testDoubles/loggerFake')
|
||||
const { removeModuleFromRequireCache, makeMockSocket, removeLibModuleCache } = require('./utils')
|
||||
|
||||
describe('realtime#update note is dirty timer', function () {
|
||||
@ -15,16 +16,11 @@ describe('realtime#update note is dirty timer', function () {
|
||||
clock = sinon.useFakeTimers({
|
||||
toFake: ['setInterval']
|
||||
})
|
||||
mock('../../dist/logger', {
|
||||
error: () => {
|
||||
}
|
||||
})
|
||||
mock('../../dist/logger', createFakeLogger())
|
||||
mock('../../dist/history', {})
|
||||
mock('../../dist/models', {
|
||||
Revision: {
|
||||
saveAllNotesRevision: () => {
|
||||
}
|
||||
}
|
||||
mock('../../dist/models', {})
|
||||
mock('../../dist/services/note', {
|
||||
saveAllNotesRevision: () => {}
|
||||
})
|
||||
mock('../../dist/config', {})
|
||||
realtime = require('../../dist/realtime/realtime')
|
||||
|
@ -19,11 +19,10 @@ describe('realtime#disconnect', function () {
|
||||
error: () => {
|
||||
}
|
||||
})
|
||||
mock('../../dist/models', {})
|
||||
mock('../../dist/history', {})
|
||||
mock('../../dist/models', {
|
||||
Revision: {
|
||||
saveAllNotesRevision: () => {
|
||||
}
|
||||
mock('../../dist/services/note', {
|
||||
saveAllNotesRevision: () => {
|
||||
}
|
||||
})
|
||||
mock('../../dist/config', {})
|
||||
|
@ -8,23 +8,22 @@ const { removeModuleFromRequireCache, removeLibModuleCache } = require('./utils'
|
||||
|
||||
describe('save revision job', function () {
|
||||
let clock
|
||||
let mockModels
|
||||
let noteService
|
||||
let realtime
|
||||
beforeEach(() => {
|
||||
removeLibModuleCache()
|
||||
mockModels = {
|
||||
Revision: {
|
||||
saveAllNotesRevision: sinon.stub()
|
||||
}
|
||||
}
|
||||
clock = sinon.useFakeTimers()
|
||||
noteService = {
|
||||
saveAllNotesRevision: sinon.stub()
|
||||
}
|
||||
mock('../../dist/processQueue', require('../testDoubles/ProcessQueueFake'))
|
||||
mock('../../dist/logger', {
|
||||
error: () => {},
|
||||
info: () => {}
|
||||
})
|
||||
mock('../../dist/history', {})
|
||||
mock('../../dist/models', mockModels)
|
||||
mock('../../dist/models', { })
|
||||
mock('../../dist/services/note', noteService)
|
||||
mock('../../dist/config', {
|
||||
debug: true
|
||||
})
|
||||
@ -41,28 +40,28 @@ describe('save revision job', function () {
|
||||
})
|
||||
|
||||
it('should execute save revision job every 5 min', (done) => {
|
||||
mockModels.Revision.saveAllNotesRevision.callsFake((callback) => {
|
||||
noteService.saveAllNotesRevision.callsFake((callback) => {
|
||||
callback(null, [])
|
||||
})
|
||||
realtime = require('../../dist/realtime/realtime')
|
||||
clock.tick(5 * 60 * 1000)
|
||||
clock.restore()
|
||||
setTimeout(() => {
|
||||
assert(mockModels.Revision.saveAllNotesRevision.called)
|
||||
assert(noteService.saveAllNotesRevision.called)
|
||||
assert(realtime.saveRevisionJob.getSaverSleep() === true)
|
||||
done()
|
||||
}, 50)
|
||||
})
|
||||
|
||||
it('should not set saverSleep when more than 1 note save revision', (done) => {
|
||||
mockModels.Revision.saveAllNotesRevision.callsFake((callback) => {
|
||||
noteService.saveAllNotesRevision.callsFake((callback) => {
|
||||
callback(null, [1])
|
||||
})
|
||||
realtime = require('../../dist/realtime/realtime')
|
||||
clock.tick(5 * 60 * 1000)
|
||||
clock.restore()
|
||||
setTimeout(() => {
|
||||
assert(mockModels.Revision.saveAllNotesRevision.called)
|
||||
assert(noteService.saveAllNotesRevision.called)
|
||||
assert(realtime.saveRevisionJob.getSaverSleep() === false)
|
||||
done()
|
||||
}, 50)
|
||||
|
@ -4,6 +4,7 @@
|
||||
const assert = require('assert')
|
||||
const mock = require('mock-require')
|
||||
const sinon = require('sinon')
|
||||
const { createFakeLogger } = require('../testDoubles/loggerFake')
|
||||
|
||||
const { makeMockSocket, removeModuleFromRequireCache } = require('./utils')
|
||||
|
||||
@ -64,16 +65,15 @@ describe('realtime#socket event', function () {
|
||||
locked: 'locked',
|
||||
protected: 'protected',
|
||||
private: 'private'
|
||||
}
|
||||
}
|
||||
mock('../../dist/logger', {
|
||||
error: () => {
|
||||
},
|
||||
info: () => {
|
||||
}
|
||||
})
|
||||
db: {}
|
||||
}
|
||||
mock('../../dist/logger', createFakeLogger())
|
||||
mock('../../dist/history', {})
|
||||
mock('../../dist/models', modelsMock)
|
||||
mock('../../dist/services/note', {
|
||||
saveAllNotesRevision: () => {}
|
||||
})
|
||||
mock('../../dist/config', configMock)
|
||||
mock('ot', require('../testDoubles/otFake'))
|
||||
realtime = require('../../dist/realtime/realtime')
|
||||
|
@ -8,7 +8,14 @@ function createFakeLogger () {
|
||||
warn: sinon.stub(),
|
||||
info: sinon.stub(),
|
||||
debug: sinon.stub(),
|
||||
log: sinon.stub()
|
||||
log: sinon.stub(),
|
||||
logger: {
|
||||
error: sinon.stub(),
|
||||
warn: sinon.stub(),
|
||||
info: sinon.stub(),
|
||||
debug: sinon.stub(),
|
||||
log: sinon.stub()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,8 @@ class EditorSocketIOServerFake {
|
||||
this.setColor = sinon.stub()
|
||||
this.getClient = sinon.stub()
|
||||
this.onDisconnect = sinon.stub()
|
||||
this.setLogger = sinon.stub()
|
||||
this.setDocumentMaxLength = sinon.stub()
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user