Passed
Push — master ( 3b3ae1...0bee8f )
by Dmytro
02:00
created

tests/requests/express.client.test.js   A

Complexity

Total Complexity 5
Complexity/F 1.25

Size

Lines of Code 64
Function Count 4

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 29
mnd 1
bc 1
fnc 4
dl 0
loc 64
rs 10
bpm 0.25
cpm 1.25
noi 0
c 0
b 0
f 0
1
import { assert } from 'chai';
2
import axios from 'axios';
3
import { users } from '../mock/fixtures';
4
import Test from '../Test';
5
import { mockAppUrl } from '../constants';
6
import chronicle, { middlewares } from '../entry';
7
8
suite('Express');
9
10
const factory = new Test(chronicle);
11
const expressMiddleWare = middlewares.express(chronicle);
12
13
before(async function () {
14
    await factory.setTmpFolder();
15
    factory.mockApp.use(expressMiddleWare(req => {
16
        return {
17
            group : 'Users',
18
            title : req.url.includes('limit=10') ? 'With limit' : 'general'
19
        };
20
    }));
21
    await factory.startMockApp();
22
});
23
24
test('Express middleware for get json array', async function () {
25
    const response = await axios(`${mockAppUrl}/api/users?limit=10`);
26
    const body = response.data;
27
28
    assert.isArray(body);
29
    assert.isNotEmpty(body);
30
    assert.deepEqual(body, users);
31
    const context = { title: 'With limit', group: 'Users' };
32
33
    factory.ensureAction(context, {
34
        method : 'GET',
35
        path   : '/api/users',
36
        body
37
    });
38
});
39
40
// test('Axios default function request with chronicle', async function () {
41
//     const data =  users.find(u => u.id === 2);
42
//     const context = { title: 'success is', group: 'wrong' };
43
44
//     delete data.id;
45
//     const response = await axios({
46
//         method : 'POST',
47
//         url    : `${mockAppUrl}/users`,
48
//         data,
49
//         with   : context
50
//     });
51
52
//     assert.deepOwnInclude(response.data, data);
53
54
//     factory.ensureAction(context, {
55
//         method : 'POST',
56
//         path   : '/users',
57
//         body   : data
58
//     });
59
// });
60
61
62
after(async function () {
63
    await factory.cleanup();
64
});
65