forked from howdyai/botkit
/
Slack_web_api.js
109 lines (91 loc) · 2.77 KB
/
Slack_web_api.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
var should = require('should');
var Botkit = require('../');
var path = require('path');
var tmpdir = require('os').tmpdir();
var fs = require('fs');
var winston = require('winston');
var token = process.env.TOKEN;
describe('Test', function() {
it('should have a token', function(done) {
should.exist(token);
done();
});
it('should have Botkit instance', function(done) {
should.exist(Botkit);
should.exist(Botkit.core);
should.exist(Botkit.slackbot);
done();
});
});
describe('Botkit', function() {
this.timeout(5000);
it('should return a package version number', function(done){
var controller = Botkit.slackbot({debug: false});
should.exist(controller.version());
done();
});
it('should start and then stop', function(done) {
var controller = Botkit.slackbot({debug: false});
var openIsCalled = false;
controller.on('rtm_open', function(bot) {
should.exist(bot);
openIsCalled = true;
});
controller.on('rtm_close', function(bot) {
should.exist(bot);
openIsCalled.should.be.true;
controller.shutdown();
done();
});
controller
.spawn({
token: token
})
.startRTM(function(err, bot, payload) {
(err === null).should.be.true;
should.exist(bot);
bot.closeRTM();
});
});
it('should have fail with false token', function(done) {
this.timeout(5000);
var controller = Botkit.slackbot({debug: false});
controller
.spawn({
token: '1234'
})
.startRTM(function(err, bot, payload) {
should.exist(err);
controller.shutdown();
done();
});
});
});
describe('Log', function() {
it('should use an external logging provider', function(done) {
var logFile = path.join(tmpdir, 'botkit.log');
var logger = new winston.Logger({
transports: [
new (winston.transports.File)({ filename: logFile })
]
});
logger.cli();
var controller = Botkit.slackbot({
debug: true,
logger: logger
});
controller
.spawn({
token: '1234'
})
.startRTM(function(err, bot, payload) {
should.exist(err);
controller.shutdown();
fs.readFile(logFile, 'utf8', function(err, res) {
(err === null).should.be.true;
should.exist(res);
done();
});
});
});
});