Total Complexity | 1 |
Complexity/F | 1 |
Lines of Code | 49 |
Function Count | 1 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import { flushPromises } from '@test/utils/testUtils'; |
||
2 | import * as http from 'http'; |
||
3 | import { Request, Response } from 'express'; |
||
4 | import supertest from 'supertest'; |
||
5 | import ExpressBeans from '@/ExpressBeans'; |
||
6 | import { Route, RouterBean } from '@/main'; |
||
7 | |||
8 | describe('ExpressBeans.ts', () => { |
||
9 | let server: http.Server; |
||
10 | let application: ExpressBeans; |
||
11 | beforeEach(async () => { |
||
12 | vi.resetModules(); |
||
13 | application = new ExpressBeans({ listen: false }); |
||
14 | server = application.getApp().listen(8080); |
||
15 | await flushPromises(); |
||
16 | }); |
||
17 | |||
18 | afterEach(() => { |
||
19 | server.close(); |
||
20 | }); |
||
21 | |||
22 | test('start of application', async () => { |
||
23 | // GIVEN |
||
24 | @RouterBean('/test') |
||
25 | class TestRouter { |
||
26 | @Route('GET', '/42') |
||
27 | test(_req: Request, res: Response) { |
||
28 | res.send('42 is the answer'); |
||
29 | } |
||
30 | } |
||
31 | application = new ExpressBeans({ listen: false, routerBeans: [TestRouter] }); |
||
32 | server = application.getApp().listen(8080); |
||
33 | |||
34 | // WHEN |
||
35 | const { body } = supertest(server).get('/test/42'); |
||
36 | |||
37 | // THEN |
||
38 | expect(body).toBe(true); |
||
39 | }); |
||
40 | |||
41 | test('creation of a new application', async () => { |
||
42 | // WHEN |
||
43 | await flushPromises(); |
||
44 | |||
45 | // THEN |
||
46 | expect(application instanceof ExpressBeans).toBe(true); |
||
47 | }); |
||
48 | }); |
||
49 |