-
Notifications
You must be signed in to change notification settings - Fork 2
/
integration.js
56 lines (51 loc) · 1.39 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
'use strict';
const runtime = require('faas-js-runtime');
const request = require('supertest');
const func = require('..');
const test = require('tape');
test('Integration: handles an HTTP GET', t => {
runtime(func, 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' }, name: 'tiger' });
t.end();
server.close();
});
}, { log: false });
});
test('Integration: handles an HTTP POST', t => {
runtime(func, 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();
});
}, { log: false });
});
test('Integration: responds with error code if neither GET or POST', t => {
runtime(func, 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();
});
}, { log: false });
});