SystemMessageManagerTests.js 1.4 KB

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