-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
86 lines (65 loc) · 1.46 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
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
var assert = require('assert')
var http = require('http')
var parse = require('url').parse
var post2sse = require('post2sse')
var WebhookPost = require('./index')
var webhook
afterEach(function()
{
webhook.close()
})
describe('Remote ServerSendEvent server', function()
{
var proxy, proxyPort
beforeEach(function(done)
{
proxy = http.createServer(post2sse()).listen(0, function()
{
proxyPort = this.address().port
done()
})
})
afterEach(function()
{
proxy.close()
})
it('Remote proxy', function(done)
{
var expected = 'asdf'
var proxyUrl = 'http://localhost:'+proxyPort+'/<ID>'
webhook = WebhookPost(proxyUrl)
.on('open', function(url)
{
assert.strictEqual(url, proxyUrl)
var requestOptions = parse(url)
requestOptions.method = 'POST'
http.request(requestOptions).end(expected)
})
.on('data', function(data)
{
assert.strictEqual(data, expected)
this.close()
})
.on('end', done)
})
})
describe('Ad-hoc local web server', function()
{
it('Local server on random port', function(done)
{
var expected = 'asdf'
webhook = WebhookPost()
.on('open', function(url)
{
var requestOptions = parse(url)
requestOptions.method = 'POST'
http.request(requestOptions).end(expected)
})
.on('data', function(data)
{
assert.strictEqual(data, expected)
this.close()
})
.on('end', done)
})
})