generated from UK-Export-Finance/nestjs-template
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d93a9da
commit be87d57
Showing
10 changed files
with
296 additions
and
234 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export * from './regex.helper'; | ||
export * from './response-status'; | ||
export * from './response-status.helper'; | ||
export * from './transform-interceptor.helper'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { HttpStatus } from '@nestjs/common'; | ||
import { isAxiosError } from 'axios'; | ||
|
||
import { statusCheck } from './response-status.helper'; | ||
|
||
jest.mock('axios', () => ({ | ||
isAxiosError: jest.fn(), | ||
})); | ||
|
||
describe('statusCheck', () => { | ||
beforeEach(() => { | ||
(isAxiosError as unknown as jest.Mock).mockReturnValue(true); | ||
}); | ||
|
||
it('should return true when isAxiosError is true and status matches', () => { | ||
const error = { | ||
response: { | ||
status: HttpStatus.BAD_REQUEST, | ||
}, | ||
name: 'Bad request', | ||
message: 'Bad request', | ||
} as Error; | ||
|
||
const result = statusCheck({ error, status: HttpStatus.BAD_REQUEST }); | ||
|
||
expect(result).toBe(true); | ||
}); | ||
|
||
it('should return false when isAxiosError is true but status does not match', () => { | ||
const error = { | ||
response: { | ||
status: HttpStatus.BAD_REQUEST, | ||
}, | ||
name: 'Bad request', | ||
message: 'Bad request', | ||
} as Error; | ||
|
||
const result = statusCheck({ error, status: HttpStatus.NOT_FOUND }); | ||
|
||
expect(result).toBe(false); | ||
}); | ||
|
||
it('should return false when isAxiosError is false', () => { | ||
const error = { | ||
response: { | ||
status: HttpStatus.BAD_REQUEST, | ||
}, | ||
name: 'Bad request', | ||
message: 'Bad request', | ||
} as Error; | ||
|
||
(isAxiosError as unknown as jest.Mock).mockReturnValue(false); | ||
|
||
const result = statusCheck({ error, status: HttpStatus.BAD_REQUEST }); | ||
|
||
expect(result).toBe(false); | ||
}); | ||
|
||
it('should return false when error does not have a response', () => { | ||
const error = {} as Error; | ||
|
||
const result = statusCheck({ error, status: HttpStatus.BAD_REQUEST }); | ||
|
||
expect(result).toBe(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters