Skip to content
Permalink
Browse files

Added UT for messenger class

  • Loading branch information
idanstark42 committed Dec 11, 2019
1 parent 59d7967 commit a71dee36e22ac3a8a73ef7ba8a015362d5ce9945
Showing with 382 additions and 6 deletions.
  1. +7 −6 lib/messenger.js
  2. +375 −0 test/lib/messenger.test.js
@@ -23,17 +23,17 @@ class Messenger {
listen (topic, callback) {
this._listenPreactions.forEach(action => { action(topic, callback, this) })

this._client.on('message', message => {
if (this._shouldHandleMessageByTopic(message, topic)) {
this.client.on('message', message => {
if (this._shouldHandleMessage(message, topic)) {
callback(message.data, message)
}
})

let promise = this.connect()
.then(() => this._client.subscribe(this.options.node, topic))
.then(() => this.client.subscribe(this.options.node, topic))

this._listenPostactions.forEach(action => {
promise = this._listenPostactions.then(result => action(result, topic, callback, this))
promise = promise.then(result => action(result, topic, callback, this))
})

return promise
@@ -50,7 +50,7 @@ class Messenger {
.then(() => this.client.publish(this.options.node, topic, data, this._headers()))

this._sendPostactions.forEach(action => {
promise = this._sendPostactions.then(result => action(result, topic, data, this))
promise = promise.then(result => action(result, topic, data, this))
})

promise.catch(error => this._sendErroractions.forEach(action => action(error)))
@@ -60,8 +60,9 @@ class Messenger {

connect () {
if (!this._connectionPromise) {
this._sendPreactions.forEach(action => { action(this) })
this._connectionPreactions.forEach(action => { action(this) })

this._connectionPromise =
this._connectionPromise = this.Promise.resolve(this.client.connect())

this._connectionPostactions.forEach(action => {

0 comments on commit a71dee3

Please sign in to comment.
You can’t perform that action at this time.