forked from skye2k2/pr-police
-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
48 lines (36 loc) · 988 Bytes
/
server.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
const test = require('tape')
const proxyquire = require('proxyquire')
const sinon = require('sinon')
const SlackbotsMock = function SlackbotsMock () {}
SlackbotsMock.prototype.on = sinon.stub()
SlackbotsMock.prototype.on.withArgs('start').yields(true)
const envMock = {
SLACK_TOKEN: 'foo',
GH_TOKEN: 'foo',
SLACK_CHANNELS: 'foo',
GH_REPOS: 'foo',
CHECK_INTERVAL: '1'
}
const pullhubMock = sinon.stub().resolves([])
const clock = sinon.useFakeTimers()
const server = proxyquire('../lib/server', {
slackbots: SlackbotsMock,
pullhub: pullhubMock
})
test('it throws error on missing required env var', (t) => {
t.plan(1)
t.throws(server, Error)
})
test('it calls slackbots onStart handler', (t) => {
t.plan(1)
process.env = envMock
server()
t.ok(SlackbotsMock.prototype.on.calledWith('start'))
})
test('it calls pullhub on start', (t) => {
t.plan(1)
process.env = envMock
server()
clock.tick(envMock.CHECK_INTERVAL)
t.ok(pullhubMock.called)
})