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
|
|
|
|