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() {
|
|
|
|
this.SystemMessage = {}
|
|
|
|
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())
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('getMessage', function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
this.messages = ['messages-stub']
|
|
|
|
return (this.SystemMessage.find = sinon
|
|
|
|
.stub()
|
|
|
|
.callsArgWith(1, null, this.messages))
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('when the messages are not cached', function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
return this.SystemMessageManager.getMessages(this.callback)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should look the messages up in the database', function() {
|
|
|
|
return this.SystemMessage.find.calledWith({}).should.equal(true)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should return the messages', function() {
|
|
|
|
return this.callback.calledWith(null, this.messages).should.equal(true)
|
|
|
|
})
|
|
|
|
|
2019-06-21 09:46:09 -04:00
|
|
|
it('should cache the messages', function() {
|
2019-05-29 05:21:06 -04:00
|
|
|
return this.SystemMessageManager._cachedMessages.should.equal(
|
|
|
|
this.messages
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-06-21 09:46:09 -04:00
|
|
|
describe('when the messages are cached', function() {
|
2019-05-29 05:21:06 -04:00
|
|
|
beforeEach(function() {
|
|
|
|
this.SystemMessageManager._cachedMessages = this.messages
|
|
|
|
return this.SystemMessageManager.getMessages(this.callback)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should not look the messages up in the database', function() {
|
|
|
|
return this.SystemMessage.find.called.should.equal(false)
|
|
|
|
})
|
|
|
|
|
2019-06-21 09:46:09 -04:00
|
|
|
it('should return the messages', function() {
|
2019-05-29 05:21:06 -04:00
|
|
|
return this.callback.calledWith(null, this.messages).should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-06-21 09:46:09 -04:00
|
|
|
describe('clearMessages', function() {
|
2019-05-29 05:21:06 -04:00
|
|
|
beforeEach(function() {
|
|
|
|
this.SystemMessage.remove = sinon.stub().callsArg(1)
|
|
|
|
return this.SystemMessageManager.clearMessages(this.callback)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should remove the messages from the database', function() {
|
|
|
|
return this.SystemMessage.remove.calledWith({}).should.equal(true)
|
|
|
|
})
|
|
|
|
|
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)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|