2019-10-20 17:36:09 +02:00
|
|
|
'use strict'
|
|
|
|
process.env.NODE_ENV = 'production'
|
|
|
|
require('chai').should()
|
|
|
|
const mock = require('mock-require')
|
|
|
|
const sinon = require('sinon')
|
|
|
|
|
|
|
|
describe('Server', () => {
|
|
|
|
let xmppStub, webhookStub
|
|
|
|
|
|
|
|
before('Setup', (done) => {
|
|
|
|
// mock XMPP component
|
|
|
|
xmppStub = sinon.stub()
|
|
|
|
webhookStub = sinon.stub()
|
|
|
|
mock('./../lib/xmpp', () => {
|
2019-11-21 01:44:43 +01:00
|
|
|
this.send = () => {}
|
|
|
|
this.close = () => {}
|
2019-10-20 17:36:09 +02:00
|
|
|
xmppStub()
|
2019-11-21 01:44:43 +01:00
|
|
|
return this
|
2019-10-20 17:36:09 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
// mock webhook component
|
|
|
|
mock('./../lib/webhook', webhookStub)
|
|
|
|
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
|
|
|
|
after('Remove mock', () => {
|
|
|
|
mock.stopAll()
|
|
|
|
})
|
|
|
|
|
|
|
|
beforeEach('Reset stub', (done) => {
|
|
|
|
xmppStub.resetHistory()
|
|
|
|
webhookStub.resetHistory()
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('Start server', () => {
|
|
|
|
it('Should call XMPP and webhook components', (done) => {
|
|
|
|
require('../lib/server')
|
|
|
|
sinon.assert.calledOnce(xmppStub)
|
|
|
|
sinon.assert.calledOnce(webhookStub)
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|