-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
61 lines (50 loc) · 1.02 KB
/
test.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
'use strict'
import nock from 'nock'
import { request } from 'http'
import test from 'tape'
const TOKEN = 'foo'
const WEBHOOK_URL_FRAG = 'bar'
let port
let server
test('setup', t => {
t.plan(2)
process.env.TOKENS_URLS = `{
"${TOKEN}":"https://hooks.slack.com/services/${WEBHOOK_URL_FRAG}"
}`
server = require('./server')
server.listen(0, err => {
t.error(err)
t.ok(port = server.address().port)
})
})
test('should send to slack channel', t => {
t.plan(3)
nock('https://hooks.slack.com:443')
.post(
`/services/${WEBHOOK_URL_FRAG}`,
body => {
t.equal(body.channel, '#robots')
t.ok(body.text)
return true
}
)
.reply(200, 'ok')
nock.enableNetConnect(`localhost:${port}`)
const req = request(
{
method: 'POST',
port: port
},
res => {
t.equal(res.statusCode, 200)
}
)
req.write(`token=${TOKEN}&channel_name=robots`)
req.end()
})
test('teardown', t => {
t.plan(1)
server.close(err => {
t.error(err)
})
})