mirror of
https://github.com/jlengrand/adyen-web.git
synced 2026-03-10 08:01:22 +00:00
refactor: console a warning when no consent url
This commit is contained in:
@@ -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();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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 };
|
||||
|
||||
Reference in New Issue
Block a user