Skip to content

Commit

Permalink
Merge pull request #1221 from guardian/add-checkout-to-addRegionIdToS…
Browse files Browse the repository at this point in the history
…upportUrl

feat: add checkout to addRegionIdToSupportUrl
  • Loading branch information
jamesgorrie authored Sep 19, 2024
2 parents 6ff3c56 + d7400c3 commit 1d84d16
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
20 changes: 20 additions & 0 deletions packages/shared/src/lib/geolocation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ describe('getCountryName', () => {

describe('addRegionIdToSupportUrl', () => {
const originalUrl = 'https://support.theguardian.com/contribute';
const checkoutUrl = 'https://support.theguardian.com/checkout';

it('should modify the URL to include UK if country code is GB', () => {
const countryCode = 'GB';
const modifiedUrl = addRegionIdToSupportUrl(originalUrl, countryCode);
Expand All @@ -50,6 +52,24 @@ describe('addRegionIdToSupportUrl', () => {
expect(modifiedUrl).toEqual('https://support.theguardian.com/int/contribute');
});

it('should modify the URL to include UK if country code is GB and URL is checkout', () => {
const countryCode = 'GB';
const modifiedUrl = addRegionIdToSupportUrl(checkoutUrl, countryCode);
expect(modifiedUrl).toEqual('https://support.theguardian.com/uk/checkout');
});

it('should modify the URL to include EU if country code is PT and URL is checkout', () => {
const countryCode = 'PT';
const modifiedUrl = addRegionIdToSupportUrl(checkoutUrl, countryCode);
expect(modifiedUrl).toEqual('https://support.theguardian.com/eu/checkout');
});

it('should modify the URL to include INT if country code is unknown and URL is checkout', () => {
const countryCode = 'asdasd';
const modifiedUrl = addRegionIdToSupportUrl(checkoutUrl, countryCode);
expect(modifiedUrl).toEqual('https://support.theguardian.com/int/checkout');
});

it('should not modify the URL if country code is missing', () => {
const countryCode = undefined;
const modifiedUrl = addRegionIdToSupportUrl(originalUrl, countryCode);
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/src/lib/geolocation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ export const addRegionIdToSupportUrl = (originalUrl: string, countryCode?: strin
const supportRegionId = countryCodeToSupportRegionId(countryCode);
if (supportRegionId && !isGWCheckoutUrl(originalUrl)) {
return originalUrl.replace(
/(support.theguardian.com)\/(contribute-in-epic|contribute|subscribe)/,
/(support\.theguardian\.com)\/(contribute-in-epic|contribute|subscribe|checkout)/,
(_, domain, path) => `${domain}/${supportRegionId.toLowerCase()}/${path}`,
);
}
Expand Down

0 comments on commit 1d84d16

Please sign in to comment.