hubot-slack
Version:
A Slack adapter for hubot
78 lines (63 loc) • 2.49 kB
text/coffeescript
{RtmClient, WebClient, MemoryDataStore} = require '@slack/client'
SlackFormatter = require '../src/formatter'
should = require 'should'
describe 'Init', ->
it 'Should initialize with a rtm connection', ->
(.rtm instanceof RtmClient).should.equal true
.rtm._token.should.equal 'xoxb-faketoken'
it 'Should initialize with a web connection', ->
(.web instanceof WebClient).should.equal true
.web._token.should.equal 'xoxb-faketoken'
it 'Should initialize with a SlackFormatter', ->
(.format instanceof SlackFormatter).should.equal true
it 'Should initialize with an empty listener', ->
.listeners.length.should.equal 0
describe 'connect()', ->
it 'Should be able to connect', ->
.connect();
._connected.should.equal true
describe 'on()', ->
it 'Should open with a new connection', ->
.on 'test', ->
.listeners.length.should.equal 1
it 'Should open with a new message connection', ->
.on 'message', ->
.listeners.length.should.equal 1
it 'Should hit a provided callback', ->
= false
.on 'message', (msg) =>
msg.should.equal 'message'
= true
.should.equal true
it 'Should open with a new message connection', ->
.on 'channel_joined', ->
.listeners.length.should.equal 1
it 'Should hit a provided callback with non-message messages', ->
= false
.on 'foo', (msg) =>
msg.should.equal 'foo'
= true
.should.equal true
describe 'disconnect()', ->
it 'Should disconnect all connections', ->
.on 'test', ->
.listeners.length.should.equal 1
.disconnect()
.listeners.length.should.equal 0
describe 'setTopic()', ->
it "Should set the topic", ->
.setTopic 12, 'iAmTopic'
._topic.should.equal 'iAmTopic'
describe 'send()', ->
it 'Should send a plain string message to room', ->
.send {room: 'room1'}, 'Message'
._msg.should.equal 'Message'
._room.should.equal 'room1'
it 'Should send an object message to room', ->
.send {room: 'room2'}, {text: 'textMessage'}
._msg.should.equal 'textMessage'
._room.should.equal 'room2'
it 'Should send an object message to room', ->
.send {room: 'room3'}, '<test|test>'
._msg.should.equal '<test|test>'
._room.should.equal 'room3'