Skip to content

Commit

Permalink
Merge pull request #1390 from slawekzachcial/robot-helpers-delegation
Browse files Browse the repository at this point in the history
Fix robot helpers delegation to adapter and events
  • Loading branch information
mose authored Sep 16, 2017
2 parents 6bdf3e2 + d1546fe commit 97f8c2f
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/robot.js
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ class Robot {
send (envelope/* , ...strings */) {
const strings = [].slice.call(arguments, 1)

this.adapter.send.apply(this, [envelope].concat(strings))
this.adapter.send.apply(this.adapter, [envelope].concat(strings))
}

// Public: A helper reply function which delegates to the adapter's reply
Expand All @@ -592,7 +592,7 @@ class Robot {
reply (envelope/* , ...strings */) {
const strings = [].slice.call(arguments, 1)

this.adapter.reply.apply(this, [envelope].concat(strings))
this.adapter.reply.apply(this.adapter, [envelope].concat(strings))
}

// Public: A helper send function to message a room that the robot is in.
Expand All @@ -605,7 +605,7 @@ class Robot {
const strings = [].slice.call(arguments, 1)
const envelope = { room }

this.adapter.send.apply(this, [envelope].concat(strings))
this.adapter.send.apply(this.adapter, [envelope].concat(strings))
}

// Public: A wrapper around the EventEmitter API to make usage
Expand All @@ -619,7 +619,7 @@ class Robot {
on (event/* , ...args */) {
const args = [].slice.call(arguments, 1)

this.events.on.apply(this, [event].concat(args))
this.events.on.apply(this.events, [event].concat(args))
}

// Public: A wrapper around the EventEmitter API to make usage
Expand All @@ -632,7 +632,7 @@ class Robot {
emit (event/* , ...args */) {
const args = [].slice.call(arguments, 1)

this.events.emit.apply(this, [event].concat(args))
this.events.emit.apply(this.events, [event].concat(args))
}

// Public: Kick off the event loop for the adapter
Expand Down
55 changes: 55 additions & 0 deletions test/robot_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,61 @@ describe('Robot', function () {
})
})
})

describe('#send', function () {
beforeEach(function () {
sinon.spy(this.robot.adapter, 'send')
})

it('delegates to adapter "send" with proper context', function () {
this.robot.send({}, 'test message')
expect(this.robot.adapter.send).to.have.been.calledOn(this.robot.adapter)
})
})

describe('#reply', function () {
beforeEach(function () {
sinon.spy(this.robot.adapter, 'reply')
})

it('delegates to adapter "reply" with proper context', function () {
this.robot.reply({}, 'test message')
expect(this.robot.adapter.reply).to.have.been.calledOn(this.robot.adapter)
})
})

describe('#messageRoom', function () {
beforeEach(function () {
sinon.spy(this.robot.adapter, 'send')
})

it('delegates to adapter "send" with proper context', function () {
this.robot.messageRoom('testRoom', 'messageRoom test')
expect(this.robot.adapter.send).to.have.been.calledOn(this.robot.adapter)
})
})

describe('#on', function () {
beforeEach(function () {
sinon.spy(this.robot.events, 'on')
})

it('delegates to events "on" with proper context', function () {
this.robot.on('event', function () {})
expect(this.robot.events.on).to.have.been.calledOn(this.robot.events)
})
})

describe('#emit', function () {
beforeEach(function () {
sinon.spy(this.robot.events, 'emit')
})

it('delegates to events "emit" with proper context', function () {
this.robot.emit('event', function () {})
expect(this.robot.events.emit).to.have.been.calledOn(this.robot.events)
})
})
})

describe('Listener Registration', function () {
Expand Down

0 comments on commit 97f8c2f

Please sign in to comment.