SystemMessageManagerTests.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* eslint-disable
  2. max-len,
  3. no-return-assign,
  4. no-unused-vars,
  5. */
  6. // TODO: This file was created by bulk-decaffeinate.
  7. // Fix any style issues and re-enable lint.
  8. /*
  9. * decaffeinate suggestions:
  10. * DS102: Remove unnecessary code created because of implicit returns
  11. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  12. */
  13. const SandboxedModule = require('sandboxed-module')
  14. const assert = require('assert')
  15. const sinon = require('sinon')
  16. const modulePath = require('path').join(
  17. __dirname,
  18. '../../../../app/src/Features/SystemMessages/SystemMessageManager.js'
  19. )
  20. describe('SystemMessageManager', function () {
  21. beforeEach(function () {
  22. this.messages = ['messages-stub']
  23. this.SystemMessage = {
  24. find: sinon.stub().yields(null, this.messages),
  25. }
  26. this.SystemMessageManager = SandboxedModule.require(modulePath, {
  27. requires: {
  28. '../../models/SystemMessage': { SystemMessage: this.SystemMessage },
  29. },
  30. })
  31. return (this.callback = sinon.stub())
  32. })
  33. it('should look the messages up in the database on import', function () {
  34. sinon.assert.called(this.SystemMessage.find)
  35. })
  36. describe('getMessage', function () {
  37. beforeEach(function () {
  38. this.SystemMessageManager._cachedMessages = this.messages
  39. return this.SystemMessageManager.getMessages(this.callback)
  40. })
  41. it('should return the messages', function () {
  42. return this.callback.calledWith(null, this.messages).should.equal(true)
  43. })
  44. })
  45. describe('clearMessages', function () {
  46. beforeEach(function () {
  47. this.SystemMessage.deleteMany = sinon.stub().callsArg(1)
  48. return this.SystemMessageManager.clearMessages(this.callback)
  49. })
  50. it('should remove the messages from the database', function () {
  51. return this.SystemMessage.deleteMany.calledWith({}).should.equal(true)
  52. })
  53. it('should return the callback', function () {
  54. return this.callback.called.should.equal(true)
  55. })
  56. })
  57. })