|
1
|
|
|
/** global: jest */ |
|
2
|
|
|
|
|
3
|
|
|
const router = require('./../../../src/routes/index'); |
|
4
|
|
|
|
|
5
|
|
|
describe('Index routes.', () => { |
|
6
|
|
|
test('GET homepage', (done) => { |
|
7
|
|
|
const request = { |
|
8
|
|
|
method: 'GET', |
|
9
|
|
|
url: '/', |
|
10
|
|
|
}; |
|
11
|
|
|
const response = { |
|
12
|
|
|
redirect: (targetUrl) => { |
|
13
|
|
|
expect(targetUrl).toMatch(/.+/); |
|
14
|
|
|
done(); |
|
15
|
|
|
}, |
|
16
|
|
|
}; |
|
17
|
|
|
|
|
18
|
|
|
router.handle(request, response); |
|
19
|
|
|
}); |
|
20
|
|
|
|
|
21
|
|
|
test('GET page by streamId', (done) => { |
|
22
|
|
|
const request = { |
|
23
|
|
|
method: 'GET', |
|
24
|
|
|
url: '/testId', |
|
25
|
|
|
}; |
|
26
|
|
|
const response = { |
|
27
|
|
|
render: (tpl, data) => { |
|
28
|
|
|
expect(tpl).toBe('index'); |
|
29
|
|
|
expect(typeof data).toBe('object'); |
|
30
|
|
|
done(); |
|
31
|
|
|
}, |
|
32
|
|
|
}; |
|
33
|
|
|
|
|
34
|
|
|
router.handle(request, response); |
|
35
|
|
|
}); |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* This block describes test cases related to POSTing data into page. |
|
39
|
|
|
*/ |
|
40
|
|
|
describe('POST data into page with certain streamId.', () => { |
|
41
|
|
|
test('POST plain text', (done) => { |
|
42
|
|
|
const request = { |
|
43
|
|
|
method: 'POST', |
|
44
|
|
|
url: '/testId', |
|
45
|
|
|
headers: { |
|
46
|
|
|
'x-forwarded-for': 'testIp', |
|
47
|
|
|
'content-type': 'text', |
|
48
|
|
|
}, |
|
49
|
|
|
body: 'Test with plain text body.', |
|
50
|
|
|
}; |
|
51
|
|
|
const response = { |
|
52
|
|
|
status: jest.fn(), |
|
53
|
|
|
send: () => done(), |
|
54
|
|
|
}; |
|
55
|
|
|
|
|
56
|
|
|
router.handle(request, response); |
|
57
|
|
|
}); |
|
58
|
|
|
|
|
59
|
|
|
test('POST JSON data', (done) => { |
|
60
|
|
|
const request = { |
|
61
|
|
|
method: 'POST', |
|
62
|
|
|
url: '/testId', |
|
63
|
|
|
headers: { 'content-type': 'application/json' }, |
|
64
|
|
|
connection: { |
|
65
|
|
|
socket: { remoteAddress: 'testIp' }, |
|
66
|
|
|
}, |
|
67
|
|
|
socket: {}, |
|
68
|
|
|
body: '{"decs": "JSON data"}', |
|
69
|
|
|
}; |
|
70
|
|
|
const response = { |
|
71
|
|
|
status: jest.fn(), |
|
72
|
|
|
send: jest.fn(), |
|
73
|
|
|
}; |
|
74
|
|
|
global.socket = { |
|
75
|
|
|
emit: (type, data) => { |
|
76
|
|
|
expect(type).toBe('log'); |
|
77
|
|
|
expect(typeof data).toBe('object'); |
|
78
|
|
|
done(); |
|
79
|
|
|
}, |
|
80
|
|
|
}; |
|
81
|
|
|
|
|
82
|
|
|
router.handle(request, response); |
|
83
|
|
|
}); |
|
84
|
|
|
}); |
|
85
|
|
|
}); |
|
86
|
|
|
|