-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
48 lines (40 loc) · 1.07 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
'use strict';
const test = require('ava');
const { createApp, getToken } = require('mm-test');
const client = require('./index');
process.env.NODE_ENV = '';
const app = createApp({}, {
auth: 'test',
test: true
});
const mm = client({ host: 'localhost:3000' });
test('checks the app', t => t.true(app.inited))
test('calls the discovery request', t => mm('?')
.then(res => {
t.is(res[0], 'test');
})
)
test('calls the discovery request', t => mm('test?')
.then(res => {
t.is(res[0], 'echo');
t.is(res[1], 'error');
})
)
test('calls the discovery request', t => mm('test.echo?')
.then(res => {
t.is(typeof res, 'object');
t.truthy(res.request);
t.truthy(res.response);
t.truthy(res.title);
t.truthy(res.description);
})
)
test('checks the error response', t => mm('test.error', { mm: 'NotFound' })
.catch(err => {
t.is(err.code, 4540);
})
)
test('calls the authorized request', t => getToken(app, { provider: 'test' })
.then(token => mm('test.echo', { hello: 'world' }, { meta: token.token }))
.then(res => t.is(res.hello, 'world'))
)