Passed
Pull Request — main (#1)
by Pieter Epeüs
01:51
created

src/__tests__/api.feature.js   A

Complexity

Total Complexity 12
Complexity/F 1

Size

Lines of Code 55
Function Count 12

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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