mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-27 19:11:56 +02:00
[web] Convert some Features files to ES modules (part 4) GitOrigin-RevId: cf11a7584e39c4d4de08e2f924240e488a4066c4
51 lines
1.4 KiB
JavaScript
51 lines
1.4 KiB
JavaScript
import { vi } from 'vitest'
|
|
import sinon from 'sinon'
|
|
|
|
const modulePath =
|
|
'../../../../app/src/Features/SystemMessages/SystemMessageManager.mjs'
|
|
|
|
describe('SystemMessageManager', function () {
|
|
beforeEach(async function (ctx) {
|
|
ctx.messages = ['messages-stub']
|
|
ctx.SystemMessage = {
|
|
find: sinon.stub().returns({
|
|
exec: sinon.stub().resolves(ctx.messages),
|
|
}),
|
|
}
|
|
|
|
vi.doMock('../../../../app/src/models/SystemMessage', () => ({
|
|
SystemMessage: ctx.SystemMessage,
|
|
}))
|
|
|
|
ctx.SystemMessageManager = (await import(modulePath)).default
|
|
})
|
|
|
|
it('should look the messages up in the database on import', function (ctx) {
|
|
sinon.assert.called(ctx.SystemMessage.find)
|
|
})
|
|
|
|
describe('getMessage', function () {
|
|
beforeEach(function (ctx) {
|
|
ctx.SystemMessageManager._cachedMessages = ctx.messages
|
|
ctx.result = ctx.SystemMessageManager.getMessages()
|
|
})
|
|
|
|
it('should return the messages', function (ctx) {
|
|
ctx.result.should.equal(ctx.messages)
|
|
})
|
|
})
|
|
|
|
describe('clearMessages', function () {
|
|
beforeEach(function (ctx) {
|
|
ctx.SystemMessage.deleteMany = sinon.stub().returns({
|
|
exec: sinon.stub().resolves(),
|
|
})
|
|
ctx.SystemMessageManager.promises.clearMessages()
|
|
})
|
|
|
|
it('should remove the messages from the database', function (ctx) {
|
|
ctx.SystemMessage.deleteMany.calledWith({}).should.equal(true)
|
|
})
|
|
})
|
|
})
|