| Total Complexity | 1 |
| Complexity/F | 1 |
| Lines of Code | 50 |
| 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 request 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(() => { |
||
| 12 | jest.resetModules(); |
||
| 13 | }); |
||
| 14 | |||
| 15 | afterEach(() => { |
||
| 16 | server.close(); |
||
| 17 | }); |
||
| 18 | |||
| 19 | test('start of application', async () => { |
||
| 20 | // GIVEN |
||
| 21 | @RouterBean('/test') |
||
| 22 | class TestRouter { |
||
| 23 | @Route('GET', '/42') |
||
| 24 | test(_req: Request, res: Response) { |
||
| 25 | res.send('42 is the answer'); |
||
| 26 | } |
||
| 27 | } |
||
| 28 | application = new ExpressBeans({ listen: false, routerBeans: [TestRouter] }); |
||
| 29 | await flushPromises(); |
||
| 30 | server = application.listen(3001); |
||
| 31 | await flushPromises(); |
||
| 32 | |||
| 33 | // WHEN |
||
| 34 | const { text } = await request(server).get('/test/42').expect(200); |
||
| 35 | |||
| 36 | // THEN |
||
| 37 | expect(text).toBe('42 is the answer'); |
||
| 38 | }); |
||
| 39 | |||
| 40 | test('creation of a new application', async () => { |
||
| 41 | // WHEN |
||
| 42 | application = new ExpressBeans({ listen: false }); |
||
| 43 | server = application.getApp().listen(3000); |
||
| 44 | await flushPromises(); |
||
| 45 | |||
| 46 | // THEN |
||
| 47 | expect(application instanceof ExpressBeans).toBe(true); |
||
| 48 | }); |
||
| 49 | }); |
||
| 50 |