diff --git a/packages/lib/src/components/AfterPay/utils.test.ts b/packages/lib/src/components/AfterPay/utils.test.ts index eb7b5012..698c569f 100644 --- a/packages/lib/src/components/AfterPay/utils.test.ts +++ b/packages/lib/src/components/AfterPay/utils.test.ts @@ -21,4 +21,21 @@ describe('getConsentLinkUrl', () => { expect(getConsentLinkUrl('be', 'fr')).toBe(rivertyConsentUrlMap.be.fr); }); }); + describe('no supported country code & locale', () => { + beforeEach(() => { + console.warn = jest.fn(); + }); + test('should give a warning if no country code is provided', () => { + getConsentLinkUrl(undefined, 'en'); + expect(console.warn).toBeCalled(); + }); + test('should give a warning if wrong country code is provided', () => { + getConsentLinkUrl('WRONG', 'en'); + expect(console.warn).toBeCalled(); + }); + test('should give a warning if wrong locale is provided', () => { + getConsentLinkUrl('nl', 'fr'); + expect(console.warn).toBeCalled(); + }); + }); }); diff --git a/packages/lib/src/components/AfterPay/utils.ts b/packages/lib/src/components/AfterPay/utils.ts index 97227452..3b37dc86 100644 --- a/packages/lib/src/components/AfterPay/utils.ts +++ b/packages/lib/src/components/AfterPay/utils.ts @@ -2,7 +2,12 @@ import { rivertyConsentUrlMap } from './config'; function getConsentLinkUrl(countryCode: string, locale: string): string { const languageCode = locale?.toLowerCase().slice(0, 2); - return rivertyConsentUrlMap[countryCode?.toLowerCase()]?.[languageCode]; + const consentLink = rivertyConsentUrlMap[countryCode?.toLowerCase()]?.[languageCode]; + if (!consentLink) { + console.warn(`Cannot find a consent url for the provided countryCode: ${countryCode} and locale: ${locale}`); + return; + } + return consentLink; } export { getConsentLinkUrl };