1
|
|
|
import { expect, describe, it } from '@jest/globals'; |
2
|
|
|
import { buildResponse } from '../response.js'; |
3
|
|
|
|
4
|
|
|
const TestCases = [ |
5
|
|
|
{ |
6
|
|
|
description: |
7
|
|
|
'The statusCode should be a valid http status code, and a number', |
8
|
|
|
params: { |
9
|
|
|
statusCode: '200', |
10
|
|
|
body: {}, |
11
|
|
|
}, |
12
|
|
|
specification: {}, |
13
|
|
|
expectedResult: 'statusCode must have a valid http status code', |
14
|
|
|
}, |
15
|
|
|
{ |
16
|
|
|
description: 'The statusCode should be a valid http status code', |
17
|
|
|
params: { |
18
|
|
|
statusCode: 123, |
19
|
|
|
body: {}, |
20
|
|
|
}, |
21
|
|
|
specification: {}, |
22
|
|
|
expectedResult: 'statusCode must have a valid http status code', |
23
|
|
|
}, |
24
|
|
|
{ |
25
|
|
|
description: 'The headers should be a valid array or object', |
26
|
|
|
params: { |
27
|
|
|
statusCode: 200, |
28
|
|
|
headers: 'invalid headers', |
29
|
|
|
body: {}, |
30
|
|
|
}, |
31
|
|
|
specification: {}, |
32
|
|
|
expectedResult: 'headers must have a valid object', |
33
|
|
|
}, |
34
|
|
|
{ |
35
|
|
|
description: 'The body should be a valid array or object', |
36
|
|
|
params: { |
37
|
|
|
statusCode: 200, |
38
|
|
|
body: 'example', |
39
|
|
|
}, |
40
|
|
|
specification: {}, |
41
|
|
|
expectedResult: 'body must have a valid object', |
42
|
|
|
}, |
43
|
|
|
{ |
44
|
|
|
description: 'The specification should be a valid object', |
45
|
|
|
params: {}, |
46
|
|
|
specification: 'invalid specification', |
47
|
|
|
expectedResult: 'specification must have a valid object', |
48
|
|
|
}, |
49
|
|
|
]; |
50
|
|
|
|
51
|
|
|
describe.each(TestCases)( |
52
|
|
|
'Response entity errors', |
53
|
|
|
({ description, params, specification, expectedResult }) => { |
54
|
|
|
it(description, () => { |
55
|
|
|
expect(() => buildResponse(params, specification)).toThrow( |
56
|
|
|
expectedResult |
57
|
|
|
); |
58
|
|
|
}); |
59
|
|
|
} |
60
|
|
|
); |
61
|
|
|
|