-
Notifications
You must be signed in to change notification settings - Fork 2
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
b547a44
commit 3c5ee53
Showing
6 changed files
with
6,269 additions
and
2 deletions.
There are no files selected for viewing
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,3 @@ | ||
yarn --cwd drama-queen run format:check | ||
yarn --cwd drama-queen run lint | ||
yarn --cwd drama-queen run test |
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 |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { describe, it, expect, vi } from 'vitest' | ||
import { handleAxiosError } from './axiosError' | ||
import { AxiosError } from 'axios' | ||
|
||
vi.mock('i18n', () => ({ | ||
getTranslation: () => ({ t: (keyMessage: string) => keyMessage }), // Remplacez par la logique de traduction souhaitée | ||
})) | ||
|
||
describe('handleAxiosError', () => { | ||
it('should return a custom message for no response', () => { | ||
const error: AxiosError = { | ||
message: '', | ||
name: '', | ||
config: {}, | ||
isAxiosError: true, | ||
toJSON: () => ({}), | ||
response: undefined, | ||
} as AxiosError | ||
|
||
const result = handleAxiosError(error) | ||
expect(result.message).toBe( | ||
"Une erreur s'est produite lors du traitement de la requête. Veuillez réessayer plus tard." | ||
) | ||
}) | ||
|
||
it('should return the correct message for status 400', () => { | ||
const error: AxiosError = { | ||
response: { status: 400 } as any, | ||
message: '', | ||
name: '', | ||
config: {}, | ||
isAxiosError: true, | ||
toJSON: () => ({}), | ||
} as AxiosError | ||
|
||
const result = handleAxiosError(error) | ||
expect(result.message).toBe('400') // Assurez-vous que la traduction pour '400' est correcte | ||
}) | ||
|
||
it('should return the correct message for status 401', () => { | ||
const error: AxiosError = { | ||
response: { status: 401 } as any, | ||
message: '', | ||
name: '', | ||
config: {}, | ||
isAxiosError: true, | ||
toJSON: () => ({}), | ||
} as AxiosError | ||
|
||
const result = handleAxiosError(error) | ||
expect(result.message).toBe('401') // Assurez-vous que la traduction pour '401' est correcte | ||
}) | ||
|
||
it('should return the correct message for unknown status', () => { | ||
const error: AxiosError = { | ||
response: { status: 999 } as any, | ||
message: '', | ||
name: '', | ||
config: {}, | ||
isAxiosError: true, | ||
toJSON: () => ({}), | ||
} as AxiosError | ||
|
||
const result = handleAxiosError(error) | ||
expect(result.message).toBe('longUnknownError') // Assurez-vous que la traduction pour 'longUnknownError' est correcte | ||
}) | ||
}) |
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
Oops, something went wrong.