Passed
Pull Request — main (#2)
by Lorenzo
03:19 queued 58s
created

TestRouter   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 6
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 6
rs 10
c 0
b 0
f 0
wmc 1

1 Function

Rating   Name   Duplication   Size   Complexity  
A test 0 3 1
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