diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index bbc2df76c..d6e593536 100755 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -39,7 +39,7 @@ jobs: - run: composer install - name: Run PHP-CS-Fixer - run: vendor/bin/php-cs-fixer fix --dry-run + uses: prestashopcorp/github-action-php-cs-fixer@master phpstan: name: PHPStan diff --git a/_dev/apps/verification-tag/src/verification-tag-retriever.spec.ts b/_dev/apps/verification-tag/src/verification-tag-retriever.spec.ts index 6eb5823c6..1a03ae87b 100644 --- a/_dev/apps/verification-tag/src/verification-tag-retriever.spec.ts +++ b/_dev/apps/verification-tag/src/verification-tag-retriever.spec.ts @@ -1,7 +1,14 @@ import { HttpClientError } from "mktg-with-google-common"; import { runRetrievalOfVerificationTag } from "./verification-tag-retriever"; +import * as Sentry from '@sentry/browser'; + +jest.mock('@sentry/browser'); describe('runRetrievalOfVerificationTag', () => { + beforeEach(() => { + jest.clearAllMocks(); // Clear any previous mock calls + }); + it('runs the whole process', async () => { // prepare const fetchOnboardingMock = jest.fn(); @@ -84,4 +91,55 @@ describe('runRetrievalOfVerificationTag', () => { expect(fetchOnboardingMock).toBeCalledTimes(1); expect(fetchShopMock).toBeCalledTimes(0); }); -}); \ No newline at end of file + + it('handles 403 Forbidden error gracefully', async () => { + // prepare + const fetchOnboardingMock = jest.fn(); + const fetchShopMock = jest.fn(); + fetchOnboardingMock.mockImplementationOnce(() => { + throw new HttpClientError("subscription not found", 403); + }); + + // act + await runRetrievalOfVerificationTag(fetchOnboardingMock, fetchShopMock); + + // assert + expect(fetchOnboardingMock).toBeCalledTimes(1); + expect(fetchShopMock).toBeCalledTimes(0); + expect(Sentry.captureException).not.toHaveBeenCalled(); // Ensure Sentry is not called + }); + + it('handles 404 Not Found error', async () => { + // prepare + const fetchOnboardingMock = jest.fn(); + const fetchShopMock = jest.fn(); + fetchOnboardingMock.mockImplementationOnce(() => { + throw new HttpClientError("oh no", 404); + }); + + // act + await runRetrievalOfVerificationTag(fetchOnboardingMock, fetchShopMock); + + // assert + expect(fetchOnboardingMock).toBeCalledTimes(1); + expect(fetchShopMock).toBeCalledTimes(0); + expect(Sentry.captureException).toHaveBeenCalled(); // Ensure Sentry is called + }); + + it('stops when token retrieval fails', async () => { + // prepare + const fetchOnboardingMock = jest.fn(); + const fetchShopMock = jest.fn(); + fetchOnboardingMock.mockImplementationOnce(() => { + throw new HttpClientError("Token retrieval failed", 500); + }); + + // act + await runRetrievalOfVerificationTag(fetchOnboardingMock, fetchShopMock); + + // assert + expect(fetchOnboardingMock).toBeCalledTimes(1); + expect(fetchShopMock).toBeCalledTimes(0); + expect(Sentry.captureException).toHaveBeenCalled(); // Ensure Sentry is called + }); +}); diff --git a/_dev/apps/verification-tag/src/verification-tag-retriever.ts b/_dev/apps/verification-tag/src/verification-tag-retriever.ts index 5ebf402ee..2377f9c7b 100644 --- a/_dev/apps/verification-tag/src/verification-tag-retriever.ts +++ b/_dev/apps/verification-tag/src/verification-tag-retriever.ts @@ -22,7 +22,7 @@ export const runRetrievalOfVerificationTag = async ( onResponse: responseHandler, }, )).json(); - + // 2- Store token in shop await fetchShop("setWebsiteVerificationMeta", { websiteVerificationMeta: token, @@ -48,14 +48,18 @@ export const runRetrievalOfVerificationTag = async ( onResponse: responseHandler, }, ); - + console.info('Marketing with Google - Google Verification tag has been refreshed.'); analytics?.track('[GGL] Re-verification & claiming Succeeded'); } catch (e) { console.error('Marketing with Google - Google Verification tag refresh failed.', e); analytics?.track('[GGL] Re-verification & claiming Failed'); scope.setTag('correlationId', correlationId); - Sentry.captureException(e, scope); + + // Send error to Sentry if it's not a 403 Forbidden error + if (e.code !== 403) { + Sentry.captureException(e, scope); + } } }; @@ -82,4 +86,3 @@ const responseHandler = async (response: Response) => { } return response; }; -