Skip to content

Commit

Permalink
Apply header stamp
Browse files Browse the repository at this point in the history
  • Loading branch information
Quetzacoalt91 committed Feb 19, 2025
1 parent 1c05fae commit 5fca6b8
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 12 deletions.
18 changes: 18 additions & 0 deletions _dev/src/ts/api/axiosError.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
import { AxiosError } from 'axios';
import { ApiError, ApiResponseAction } from '../types/apiTypes';

Expand Down
42 changes: 30 additions & 12 deletions _dev/tests/components/LogsViewer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,36 +191,50 @@ describe('LogsViewer', () => {
it('should add the detailed and generic error messages', () => {
logsViewer.addError({
type: 'IRRELEVANT_CODE',
code: 404,
code: 404
});

expect(logsViewer.addLogs).toHaveBeenCalledTimes(2);
expect(logsViewer.addLogs).toHaveBeenNthCalledWith(1, [`ERROR -
expect(logsViewer.addLogs).toHaveBeenNthCalledWith(1, [
`ERROR -
The requested page or resource could not be found. This might be due to:
A broken or outdated link.
The page being moved or deleted.
A typo in the URL.`]);
expect(logsViewer.addLogs).toHaveBeenNthCalledWith(2, ['ERROR - HTTP request failed. Type: IRRELEVANT_CODE - HTTP Code: 404']);
expect((container.querySelector('#log-additional-contents') as HTMLPreElement|null)?.innerText).toBeUndefined();
A typo in the URL.`
]);
expect(logsViewer.addLogs).toHaveBeenNthCalledWith(2, [
'ERROR - HTTP request failed. Type: IRRELEVANT_CODE - HTTP Code: 404'
]);
expect(
(container.querySelector('#log-additional-contents') as HTMLPreElement | null)?.innerText
).toBeUndefined();
});

it('should only add the generic error message', () => {
logsViewer.addError({
type: 'SOME_ERROR_REASON_WE_HAVE_NOT_DETAILED',
code: 200,
code: 200
});

expect(logsViewer.addLogs).toHaveBeenCalledTimes(1);
expect(logsViewer.addLogs).toHaveBeenNthCalledWith(1, ['ERROR - HTTP request failed. Type: SOME_ERROR_REASON_WE_HAVE_NOT_DETAILED - HTTP Code: 200']);
expect((container.querySelector('#log-additional-contents') as HTMLPreElement|null)?.innerText).toBeUndefined();
expect(logsViewer.addLogs).toHaveBeenNthCalledWith(1, [
'ERROR - HTTP request failed. Type: SOME_ERROR_REASON_WE_HAVE_NOT_DETAILED - HTTP Code: 200'
]);
expect(
(container.querySelector('#log-additional-contents') as HTMLPreElement | null)?.innerText
).toBeUndefined();
});

it('should fallback when no data is provided', () => {
logsViewer.addError({});

expect(logsViewer.addLogs).toHaveBeenCalledTimes(1);
expect(logsViewer.addLogs).toHaveBeenNthCalledWith(1, ['ERROR - HTTP request failed. Type: N/A - HTTP Code: N/A']);
expect((container.querySelector('#log-additional-contents') as HTMLPreElement|null)?.innerText).toBeUndefined();
expect(logsViewer.addLogs).toHaveBeenNthCalledWith(1, [
'ERROR - HTTP request failed. Type: N/A - HTTP Code: N/A'
]);
expect(
(container.querySelector('#log-additional-contents') as HTMLPreElement | null)?.innerText
).toBeUndefined();
});

it('should add the response contents in the block when provided', () => {
Expand All @@ -231,8 +245,12 @@ describe('LogsViewer', () => {
});

expect(logsViewer.addLogs).toHaveBeenCalledTimes(1);
expect(logsViewer.addLogs).toHaveBeenNthCalledWith(1, ['ERROR - HTTP request failed. Type: ERR_BAD_RESPONSE - HTTP Code: 500']);
expect((container.querySelector('#log-additional-contents') as HTMLPreElement|null)?.innerText).toBe('Oh no!');
expect(logsViewer.addLogs).toHaveBeenNthCalledWith(1, [
'ERROR - HTTP request failed. Type: ERR_BAD_RESPONSE - HTTP Code: 500'
]);
expect(
(container.querySelector('#log-additional-contents') as HTMLPreElement | null)?.innerText
).toBe('Oh no!');
});
});
});

0 comments on commit 5fca6b8

Please sign in to comment.