mirror of
https://github.com/nioc/xmpp-bot.git
synced 2024-12-04 22:23:36 +01:00
Better handling XMPP start error
This commit is contained in:
parent
7f3de716c1
commit
f7567cd2f9
2 changed files with 31 additions and 1 deletions
|
@ -168,7 +168,7 @@ module.exports = (logger, config) => {
|
|||
// connect
|
||||
xmppClient.start()
|
||||
.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
|
||||
|
|
30
test/xmpp.js
30
test/xmpp.js
|
@ -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', () => {
|
||||
beforeEach(async () => {
|
||||
await simpleXmppEvents.emit('stanza', xml(
|
||||
|
|
Loading…
Reference in a new issue