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')
|
|
|
|
require('chai').should()
|
|
|
|
const sinon = require('sinon')
|
|
|
|
const modulePath = require('path').join(
|
|
|
|
__dirname,
|
|
|
|
'../../../../app/src/Features/SystemMessages/SystemMessageManager.js'
|
|
|
|
)
|
|
|
|
|
|
|
|
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, {
|
2019-07-15 06:33:47 -04:00
|
|
|
globals: {
|
|
|
|
console: console
|
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
requires: {
|
|
|
|
'../../models/SystemMessage': { SystemMessage: this.SystemMessage }
|
|
|
|
}
|
|
|
|
})
|
|
|
|
return (this.callback = sinon.stub())
|
|
|
|
})
|
|
|
|
|
2020-01-07 06:03:43 -05:00
|
|
|
it('should look the messages up in the database on import', function() {
|
|
|
|
sinon.assert.called(this.SystemMessage.find)
|
|
|
|
})
|
|
|
|
|
2019-05-29 05:21:06 -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
|
|
|
})
|
|
|
|
|
2020-01-07 06:03:43 -05:00
|
|
|
it('should return the messages', function() {
|
|
|
|
return this.callback.calledWith(null, this.messages).should.equal(true)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-06-21 09:46:09 -04:00
|
|
|
describe('clearMessages', function() {
|
2019-05-29 05:21:06 -04:00
|
|
|
beforeEach(function() {
|
2020-11-02 09:57:41 -05:00
|
|
|
this.SystemMessage.remove = sinon.stub().callsArg(1)
|
2019-05-29 05:21:06 -04:00
|
|
|
return this.SystemMessageManager.clearMessages(this.callback)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should remove the messages from the database', function() {
|
2020-11-02 09:57:41 -05:00
|
|
|
return this.SystemMessage.remove.calledWith({}).should.equal(true)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2019-06-21 09:46:09 -04:00
|
|
|
it('should return the callback', function() {
|
2019-05-29 05:21:06 -04:00
|
|
|
return this.callback.called.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|