SystemMessageManager.test.mjs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import { vi } from 'vitest'
  2. import sinon from 'sinon'
  3. const modulePath =
  4. '../../../../app/src/Features/SystemMessages/SystemMessageManager.mjs'
  5. describe('SystemMessageManager', function () {
  6. beforeEach(async function (ctx) {
  7. ctx.messages = ['messages-stub']
  8. ctx.SystemMessage = {
  9. find: sinon.stub().returns({
  10. exec: sinon.stub().resolves(ctx.messages),
  11. }),
  12. }
  13. vi.doMock('../../../../app/src/models/SystemMessage', () => ({
  14. SystemMessage: ctx.SystemMessage,
  15. }))
  16. ctx.SystemMessageManager = (await import(modulePath)).default
  17. })
  18. it('should look the messages up in the database on import', function (ctx) {
  19. sinon.assert.called(ctx.SystemMessage.find)
  20. })
  21. describe('getMessage', function () {
  22. beforeEach(function (ctx) {
  23. ctx.SystemMessageManager._cachedMessages = ctx.messages
  24. ctx.result = ctx.SystemMessageManager.getMessages()
  25. })
  26. it('should return the messages', function (ctx) {
  27. ctx.result.should.equal(ctx.messages)
  28. })
  29. })
  30. describe('clearMessages', function () {
  31. beforeEach(function (ctx) {
  32. ctx.SystemMessage.deleteMany = sinon.stub().returns({
  33. exec: sinon.stub().resolves(),
  34. })
  35. ctx.SystemMessageManager.promises.clearMessages()
  36. })
  37. it('should remove the messages from the database', function (ctx) {
  38. ctx.SystemMessage.deleteMany.calledWith({}).should.equal(true)
  39. })
  40. })
  41. })