|
| 1 | +import * as sinon from 'sinon'; |
| 2 | +import { expect } from 'chai'; |
| 3 | +import { transformException } from './../../../interceptors/multer/multer.utils'; |
| 4 | +import { HttpException } from '../../../../../lib/common/exceptions/http.exception'; |
| 5 | +import { multerExceptions } from '../../../interceptors/multer/multer.constants'; |
| 6 | +import { PayloadTooLargeException, BadRequestException } from '../../../exceptions'; |
| 7 | + |
| 8 | +describe('transformException', () => { |
| 9 | + describe('if error does not exist', () => { |
| 10 | + it('behave as identity', () => { |
| 11 | + const err = undefined; |
| 12 | + expect( |
| 13 | + transformException(err) |
| 14 | + ).to.be.eq(err); |
| 15 | + }); |
| 16 | + }); |
| 17 | + describe('if error is instance of HttpException', () => { |
| 18 | + it('behave as identity', () => { |
| 19 | + const err = new HttpException('response', 500); |
| 20 | + expect( |
| 21 | + transformException(err) |
| 22 | + ).to.be.eq(err); |
| 23 | + }); |
| 24 | + }); |
| 25 | + describe('if error exists and is not instance of HttpException', () => { |
| 26 | + describe('and is LIMIT_FILE_SIZE exception', () => { |
| 27 | + it('should return "PayloadTooLargeException"', () => { |
| 28 | + const err = { message: multerExceptions.LIMIT_FILE_SIZE }; |
| 29 | + expect( |
| 30 | + transformException(err as any) |
| 31 | + ).to.be.instanceof(PayloadTooLargeException); |
| 32 | + }); |
| 33 | + }); |
| 34 | + describe('and is multer exception but not a LIMIT_FILE_SIZE', () => { |
| 35 | + it('should return "BadRequestException"', () => { |
| 36 | + const err = { message: multerExceptions.LIMIT_FIELD_KEY }; |
| 37 | + expect( |
| 38 | + transformException(err as any) |
| 39 | + ).to.be.instanceof(BadRequestException); |
| 40 | + }); |
| 41 | + }); |
| 42 | + }); |
| 43 | +}); |
0 commit comments