Skip to content

Commit

Permalink
test: @res alias test case
Browse files Browse the repository at this point in the history
  • Loading branch information
jackey8616 committed Oct 3, 2024
1 parent d8c881a commit c5c6500
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/fixtures/controllers/getController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
} from '../testModel';
import { ModelService } from './../services/modelService';

export type BadRequest = TsoaResponse<400, { name: 'some_thing' }>;
export const PathFromConstant = 'PathFromConstantValue';
export enum EnumPaths {
PathFromEnum = 'PathFromEnumValue',
Expand Down Expand Up @@ -278,6 +279,14 @@ export class GetTestController extends Controller {
res?.(400, new ModelService().getModel(), { 'custom-header': 'hello' });
}

/**
* @param res The alternate response
*/
@Get('Res_Alias')
public async getResAlias(@Res() res: BadRequest): Promise<void> {
res?.(400, { name: 'some_thing' });
}

/**
* @param res The alternate response
* @param res Another alternate response
Expand Down
10 changes: 10 additions & 0 deletions tests/integration/express-server.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,16 @@ describe('Express Server', () => {
);
});

it('Should return on @Res with alias', () => {
return verifyGetRequest(
basePath + '/GetTest/Res_Alias',
(_err, res) => {
expect(res.body.name).to.equal('some_thing');
},
400,
);
});

[400, 500].forEach(statusCode =>
it('Should support multiple status codes with the same @Res structure', () => {
return verifyGetRequest(
Expand Down

0 comments on commit c5c6500

Please sign in to comment.