-
Notifications
You must be signed in to change notification settings - Fork 0
/
integration.js
61 lines (55 loc) · 1.46 KB
/
integration.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';
const { start } = require('faas-js-runtime');
const request = require('supertest');
const func = require('..').handle;
const test = require('tape');
const errHandler = t => err => {
t.error(err);
t.end();
};
test('Integration: handles an HTTP GET', t => {
start(func).then(server => {
t.plan(2);
request(server)
.get('/?name=tiger')
.expect(200)
.expect('Content-Type', /json/)
.end((err, res) => {
t.error(err, 'No error');
t.deepEqual(res.body, { query: { name: 'tiger' } });
t.end();
server.close();
});
}, errHandler(t));
});
test('Integration: handles an HTTP POST', t => {
start(func).then(server => {
t.plan(2);
request(server)
.post('/')
.send({ name: 'tiger' })
.expect(200)
.expect('Content-Type', /json/)
.end((err, res) => {
t.error(err, 'No error');
t.deepEqual(res.body, { name: 'tiger' });
t.end();
server.close();
});
}, errHandler(t));
});
test('Integration: responds with error code if neither GET or POST', t => {
start(func).then(server => {
t.plan(1);
request(server)
.put('/')
.send({ name: 'tiger' })
.expect(200)
.expect('Content-Type', /json/)
.end((err, res) => {
t.deepEqual(res.body, { message: 'Route PUT:/ not found', error: 'Not Found', statusCode: 404 });
t.end();
server.close();
});
}, errHandler(t));
});