2019-05-29 05:21:06 -04:00
|
|
|
/* eslint-disable
|
|
|
|
max-len,
|
|
|
|
no-return-assign,
|
|
|
|
no-unused-vars,
|
|
|
|
*/
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
|
|
|
const SandboxedModule = require('sandboxed-module')
|
|
|
|
const assert = require('assert')
|
|
|
|
const sinon = require('sinon')
|
|
|
|
const modulePath = require('path').join(
|
|
|
|
__dirname,
|
|
|
|
'../../../../app/src/Features/SystemMessages/SystemMessageManager.js'
|
|
|
|
)
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('SystemMessageManager', function () {
|
|
|
|
beforeEach(function () {
|
2020-01-07 06:03:43 -05:00
|
|
|
this.messages = ['messages-stub']
|
|
|
|
this.SystemMessage = {
|
|
|
|
find: sinon.stub().yields(null, this.messages)
|
|
|
|
}
|
2019-05-29 05:21:06 -04:00
|
|
|
this.SystemMessageManager = SandboxedModule.require(modulePath, {
|
|
|
|
requires: {
|
|
|
|
'../../models/SystemMessage': { SystemMessage: this.SystemMessage }
|
|
|
|
}
|
|
|
|
})
|
|
|
|
return (this.callback = sinon.stub())
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should look the messages up in the database on import', function () {
|
2020-01-07 06:03:43 -05:00
|
|
|
sinon.assert.called(this.SystemMessage.find)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('getMessage', function () {
|
|
|
|
beforeEach(function () {
|
2020-01-07 06:03:43 -05:00
|
|
|
this.SystemMessageManager._cachedMessages = this.messages
|
|
|
|
return this.SystemMessageManager.getMessages(this.callback)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should return the messages', function () {
|
2020-01-07 06:03:43 -05:00
|
|
|
return this.callback.calledWith(null, this.messages).should.equal(true)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('clearMessages', function () {
|
|
|
|
beforeEach(function () {
|
2020-11-03 04:19:05 -05:00
|
|
|
this.SystemMessage.deleteMany = sinon.stub().callsArg(1)
|
2019-05-29 05:21:06 -04:00
|
|
|
return this.SystemMessageManager.clearMessages(this.callback)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should remove the messages from the database', function () {
|
2020-11-03 04:19:05 -05:00
|
|
|
return this.SystemMessage.deleteMany.calledWith({}).should.equal(true)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should return the callback', function () {
|
2019-05-29 05:21:06 -04:00
|
|
|
return this.callback.called.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|