src/__tests__/api.feature.js   A
last analyzed

Complexity

Total Complexity 12
Complexity/F 1

Size

Lines of Code 57
Function Count 12

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 12
eloc 39
mnd 0
bc 0
fnc 12
dl 0
loc 57
rs 10
bpm 0
cpm 1
noi 0
c 0
b 0
f 0
1
import { ApiRoutes } from '../api';
2
import OpenAPISpecification from '../__fixtures__/api-doc.json';
3
import Backend from '../__mocks__/backend';
4
import callback from '../__mocks__/callback';
5
import controllers from '../__mocks__/controller';
6
7
describe('API route without security', () => {
8
    const actual = ApiRoutes.create({
9
        specification: OpenAPISpecification,
10
        Backend,
11
        controllers,
12
        callback,
13
    });
14
    it('Test if the return value is a instance of the backend', () => {
15
        expect(actual instanceof Backend).toBeTruthy();
16
    });
17
18
    it('Test if the API route add all routes', () => {
19
        expect(actual.routes.map((route) => route.operationId)).toEqual([
20
            'getStatus',
21
            'getTest',
22
            'postTest',
23
            'notFound',
24
        ]);
25
    });
26
27
    it('Test if the API security is empty', () => {
28
        expect(actual.security.map((route) => route.name)).toEqual([]);
29
    });
30
});
31
32
describe('API route with security', () => {
33
    const actual = ApiRoutes.create({
34
        specification: OpenAPISpecification,
35
        secret: 'secret',
36
        Backend,
37
        controllers,
38
        callback,
39
    });
40
    it('Test if the return value is a instance of the backend', () => {
41
        expect(actual instanceof Backend).toBeTruthy();
42
    });
43
44
    it('Test if the API route add all routes', () => {
45
        expect(actual.routes.map((route) => route.operationId)).toEqual([
46
            'unauthorizedHandler',
47
            'getStatus',
48
            'getTest',
49
            'postTest',
50
            'notFound',
51
        ]);
52
    });
53
54
    it('Test if the API security is set', () => {
55
        expect(actual.security.map((route) => route.name)).toEqual(['apiKey']);
56
    });
57
});
58