-
Notifications
You must be signed in to change notification settings - Fork 3
/
unit.js
29 lines (24 loc) · 908 Bytes
/
unit.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
'use strict';
const func = require('..').handle;
const test = require('tape');
const fixture = { log: { info: console.log } };
test('Unit: handles an HTTP GET', async t => {
t.plan(1);
// Invoke the function, which should complete without error.
const result = await func({ ...fixture, method: 'GET', query: { name: 'tiger' } });
t.deepEqual(result, { query: { name: 'tiger' } });
t.end();
});
test('Unit: handles an HTTP POST', async t => {
t.plan(1);
// Invoke the function, which should complete without error.
const result = await func({ ...fixture, method: 'POST', body: { name: 'tiger' } });
t.deepEqual(result, { body: { name: 'tiger' } });
t.end();
});
test('Unit: responds with error code if neither GET or POST', async t => {
t.plan(1);
const result = await func(fixture);
t.deepEqual(result, { statusCode: 405, statusMessage: 'Method not allowed' });
t.end();
});