|
| 1 | +import { Server as HttpServer } from 'http'; |
| 2 | +import HttpStatusCodes from 'http-status-codes'; |
| 3 | +import { Controller } from '../../src/decorator/Controller'; |
| 4 | +import { Get } from '../../src/decorator/Get'; |
| 5 | +import { createExpressServer, getMetadataArgsStorage } from '../../src/index'; |
| 6 | +import { axios } from '../utilities/axios'; |
| 7 | +import DoneCallback = jest.DoneCallback; |
| 8 | + |
| 9 | +describe(``, () => { |
| 10 | + let expressServer: HttpServer; |
| 11 | + |
| 12 | + describe('loaded direct from array', () => { |
| 13 | + let controllerOrder: number[]; |
| 14 | + |
| 15 | + beforeEach(() => { |
| 16 | + controllerOrder = []; |
| 17 | + }); |
| 18 | + |
| 19 | + beforeAll((done: DoneCallback) => { |
| 20 | + getMetadataArgsStorage().reset(); |
| 21 | + |
| 22 | + @Controller() |
| 23 | + class ThirdController { |
| 24 | + @Get('/*') |
| 25 | + getAll() { |
| 26 | + controllerOrder.push(3); |
| 27 | + return 'OK'; |
| 28 | + } |
| 29 | + } |
| 30 | + |
| 31 | + @Controller() |
| 32 | + class SecondController { |
| 33 | + @Get('/second/*') |
| 34 | + getAll() { |
| 35 | + controllerOrder.push(2); |
| 36 | + return 'OK'; |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + @Controller() |
| 41 | + class FirstController { |
| 42 | + @Get('/second/first/*') |
| 43 | + getAll() { |
| 44 | + controllerOrder.push(1); |
| 45 | + return 'OK'; |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + expressServer = createExpressServer({ |
| 50 | + controllers: [FirstController, SecondController, ThirdController], |
| 51 | + }).listen(3001, done); |
| 52 | + }); |
| 53 | + |
| 54 | + afterAll((done: DoneCallback) => expressServer.close(done)); |
| 55 | + |
| 56 | + it('should call controllers in order defined by items order', async () => { |
| 57 | + await axios.get('/second/first/any'); |
| 58 | + await axios.get('/second/any'); |
| 59 | + await axios.get('/any'); |
| 60 | + expect(controllerOrder).toEqual([1, 2, 3]); |
| 61 | + }); |
| 62 | + }); |
| 63 | +}); |
0 commit comments