Better handling XMPP start error

This commit is contained in:
nioc 2019-11-24 19:33:54 +01:00
parent 7f3de716c1
commit f7567cd2f9
2 changed files with 31 additions and 1 deletions

View file

@ -168,7 +168,7 @@ module.exports = (logger, config) => {
// connect // connect
xmppClient.start() xmppClient.start()
.catch((error) => { .catch((error) => {
logger.error('XMPP client encountered following error at connection', error) logger.error('XMPP client encountered following error at connection:', error.message)
}) })
return this return this

View file

@ -100,6 +100,36 @@ describe('XMPP component', () => {
}) })
}) })
describe('Connect to XMPP server but fail to start', () => {
let xmppStartStub
beforeEach(async () => {
xmppStartStub = sinon.stub().rejects(new Error('Stubed error message'))
mock('@xmpp/client', {
client: () => {
this.start = xmppStartStub
this.stop = xmppCloseStub
this.send = xmppSendStub
this.on = (eventName, callback) => {
simpleXmppEvents.on(eventName, callback)
}
return this
},
xml: require('@xmpp/xml'),
jid: require('@xmpp/jid')
})
xmpp = require('./../lib/xmpp')(logger, config)
})
it('Should log error', (done) => {
require('fs').readFile(config.logger.file.path + config.logger.file.filename, 'utf8', (err, data) => {
if (err) {
throw err
}
data.should.match(new RegExp('XMPP client encountered following error at connection: Stubed error message' + '\n$'))
done()
})
})
})
describe('Bot receive a presence stanza from someone', () => { describe('Bot receive a presence stanza from someone', () => {
beforeEach(async () => { beforeEach(async () => {
await simpleXmppEvents.emit('stanza', xml( await simpleXmppEvents.emit('stanza', xml(