-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
103 lines (88 loc) · 1.86 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
'use strict';
const test = require('ava');
const { createApp, createClient } = require('mm-test');
const got = require('got');
const extension = require('./index');
const httpMethodsTestApi = require('./http-test');
process.env.NODE_ENV = '';
const API_URL = 'http://localhost:3000/api';
const request = ({ method, path, body }) => got(`${API_URL}/${path}`, {
method,
json: true,
body
}).then(res => {
const msg = res.body;
if (msg[0]) {
throw msg[0];
}
return msg[1];
});
const app = createApp({
extensions: [
extension,
'serializer-json',
httpMethodsTestApi
],
serialiser: {
default: 'json'
}
}, { default: false });
const mm = createClient({ host: 'localhost:3000' })
test('checks the app', t => {
t.true(app.inited);
t.truthy(app.root);
});
test('check call request', t => mm('test.GET', { hello: 'world' })
.then(res => {
t.is(res.hello, 'world');
})
);
test('check http get request', t => request({
method: 'GET',
path: 'test'
}).then(res => {
// should be empty
t.falsy(res);
}));
test('check http get request with vars', t => request({
method: 'GET',
path: 'test?a=test'
}).then(res => {
t.is(res.a, 'test');
}));
test('check http post request with vars', t => request({
method: 'POST',
path: 'test',
body: {
a: 'test'
}
}).then(res => {
t.is(res.a, 'test');
}));
test('check http put request with vars', t => request({
method: 'PUT',
path: 'test',
body: {
a: 'test'
}
}).then(res => {
t.is(res.a, 'test');
}));
test('check http delete request with vars', t => request({
method: 'DELETE',
path: 'test',
body: {
a: 'test'
}
}).then(res => {
t.is(res.a, 'test');
}));
test('check http option request', t => request({
method: 'OPTIONS',
path: 'test'
}).then(res => {
t.is(res[0], 'GET');
t.is(res[1], 'POST');
t.is(res[2], 'PUT');
t.is(res[3], 'DELETE');
}));