Passed
Branch main (d73254)
by Pieter Epeüs
02:07
created

src/__tests__/response-errors.unit.js   A

Complexity

Total Complexity 3
Complexity/F 1

Size

Lines of Code 59
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 43
mnd 0
bc 0
fnc 3
dl 0
loc 59
rs 10
bpm 0
cpm 1
noi 1
c 0
b 0
f 0
1
import { buildJsonResponse } from '../response';
2
3
const TestCases = [
4
    {
5
        description:
6
            'The statusCode should be a valid http status code, and a number',
7
        params: {
8
            statusCode: '200',
9
            body: {},
10
        },
11
        specification: {},
12
        expectedResult: 'statusCode must have a valid http status code',
13
    },
14
    {
15
        description: 'The statusCode should be a valid http status code',
16
        params: {
17
            statusCode: 123,
18
            body: {},
19
        },
20
        specification: {},
21
        expectedResult: 'statusCode must have a valid http status code',
22
    },
23
    {
24
        description: 'The headers should be a valid array or object',
25
        params: {
26
            statusCode: 200,
27
            headers: 'invalid headers',
28
            body: {},
29
        },
30
        specification: {},
31
        expectedResult: 'headers must have a valid object',
32
    },
33
    {
34
        description: 'The body should be a valid array or object',
35
        params: {
36
            statusCode: 200,
37
            body: 'example',
38
        },
39
        specification: {},
40
        expectedResult: 'body must have a valid object',
41
    },
42
    {
43
        description: 'The specification should be a valid object',
44
        params: {},
45
        specification: 'invalid specification',
46
        expectedResult: 'specification must have a valid object',
47
    },
48
];
49
50
describe.each(TestCases)(
0 ignored issues
show
Bug introduced by
The variable describe seems to be never declared. If this is a global, consider adding a /** global: describe */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
51
    'Response entity errors',
52
    ({ description, params, specification, expectedResult }) => {
53
        it(description, () => {
54
            expect(() => buildJsonResponse(params, specification)).toThrow(
55
                expectedResult
56
            );
57
        });
58
    }
59
);
60