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

Complexity

Total Complexity 6
Complexity/F 1.5

Size

Lines of Code 49
Function Count 4

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 33
mnd 2
bc 2
fnc 4
dl 0
loc 49
rs 10
bpm 0.5
cpm 1.5
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
        if (req.url.includes('format')) {
17
            return {
18
                group : 'Format',
19
                title : req.url
20
            };
21
        }
22
23
        return {
24
            group : 'Users',
25
            title : req.url.includes('limit=10') ? 'With limit' : 'general'
26
        };
27
    }));
28
    await factory.startMockApp();
29
});
30
31
test('Express middleware for get json array', async function () {
32
    const response = await axios(`${mockAppUrl}/api/users?limit=10`);
33
    const body = response.data;
34
35
    assert.isArray(body);
36
    assert.isNotEmpty(body);
37
    assert.deepEqual(body, users);
38
    const context = { title: 'With limit', group: 'Users' };
39
40
    factory.ensureAction(context, {
41
        method : 'GET',
42
        path   : '/api/users',
43
        body
44
    });
45
});
46
47
after(async function () {
48
    await factory.cleanup();
49
});
50