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