Skip to content

Commit

Permalink
test(common): add http exception tests
Browse files Browse the repository at this point in the history
add "getStatus" tests for all HttpException children classes
  • Loading branch information
thiagomini committed Oct 27, 2022
1 parent 45b6cc1 commit ab881e3
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions packages/common/test/exceptions/http.exception.spec.ts
Expand Up @@ -63,8 +63,33 @@ describe('HttpException', () => {
describe('built-in exceptions', () => {
describe('getStatus', () => {
it('should return given status code', () => {
expect(new BadRequestException().getStatus()).to.be.eql(400);
expect(new NotFoundException().getStatus()).to.be.eql(404);
const testCases: [Type<HttpException>, number][] = [
[BadRequestException, 400],
[UnauthorizedException, 401],
[ForbiddenException, 403],
[NotFoundException, 404],
[MethodNotAllowedException, 405],
[NotAcceptableException, 406],
[RequestTimeoutException, 408],
[ConflictException, 409],
[GoneException, 410],
[PreconditionFailedException, 412],
[PayloadTooLargeException, 413],
[UnsupportedMediaTypeException, 415],
[ImATeapotException, 418],
[MisdirectedException, 421],
[UnprocessableEntityException, 422],
[InternalServerErrorException, 500],
[NotImplementedException, 501],
[BadGatewayException, 502],
[ServiceUnavailableException, 503],
[GatewayTimeoutException, 504],
[HttpVersionNotSupportedException, 505],
];

testCases.forEach(([ExceptionClass, expectedStatus]) => {
expect(new ExceptionClass().getStatus()).to.be.eql(expectedStatus);
});
});
});

Expand Down

0 comments on commit ab881e3

Please sign in to comment.