-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
84 lines (69 loc) · 1.48 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
var ifError = require('assert').ifError
var request = require('supertest')
var suppose = require('suppose')
var post2sse = require('./index.js')
const EVENTS_SEPARATOR = '\n\n'
it('fail when using an invalid HTTP method', function(done)
{
request(post2sse())
.put('/a')
.expect(405, done)
})
describe('SSE clients', function()
{
it('fail when not defined ID', function(done)
{
request(post2sse())
.get('/')
.expect(403, done)
})
it('register correctly', function(done)
{
request(post2sse())
.get('/a')
.pipe(suppose())
.when(':ok'+EVENTS_SEPARATOR, done)
})
it('fail when trying to register same ID twice', function(done)
{
var proxy = post2sse()
request(proxy)
.get('/a')
.end()
request(proxy)
.get('/a')
.expect(409, done)
})
})
describe('POST notifications', function()
{
it('fail when not defined ID', function(done)
{
request(post2sse())
.post('/')
.expect(403, done)
})
it('fail when ID is not found', function(done)
{
request(post2sse())
.post('/a')
.expect(404, done)
})
it('forward correctly a notification', function(done)
{
var data =
{
asdf: 'qwerty'
}
var proxy = post2sse()
request(proxy)
.get('/a')
.pipe(suppose())
.when(':ok'+EVENTS_SEPARATOR)
.when('data: '+JSON.stringify(data)+EVENTS_SEPARATOR, done)
request(proxy)
.post('/a')
.send(data)
.end(ifError)
})
})