Files
overleaf-cep/services/web/test/unit/src/SystemMessages/SystemMessageManager.test.mjs
Antoine Clausse 6b663a8509 Merge pull request #28544 from overleaf/ac-some-web-esm-migration-4
[web] Convert some Features files to ES modules (part 4)

GitOrigin-RevId: cf11a7584e39c4d4de08e2f924240e488a4066c4
2025-09-24 08:05:58 +00:00

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)
})
})
})