Skip to content

Commit 08da168

Browse files
author
Juarez Mota
committed
feat: add destination url prop to choice card
1 parent ad9efb5 commit 08da168

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

src/server/lib/choiceCards/choiceCards.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,35 @@ describe('getChoiceCardsSettings', () => {
9393
supportTier: 'SupporterPlus',
9494
ratePlan: 'Monthly',
9595
});
96+
expect(result?.choiceCards[1].destinationUrl).toBeNull();
97+
});
98+
99+
it('preserves custom destinationUrl when provided', () => {
100+
const variantChoiceCardSettings: ChoiceCardsSettings = {
101+
choiceCards: [
102+
{
103+
...defaultEpicChoiceCardsSettings('UnitedStates').choiceCards[0],
104+
destinationUrl: 'https://support.theguardian.com/contribute/one-time',
105+
},
106+
defaultEpicChoiceCardsSettings('UnitedStates').choiceCards[1],
107+
defaultEpicChoiceCardsSettings('UnitedStates').choiceCards[2],
108+
],
109+
};
110+
const promoCodes: string[] = [];
111+
112+
const result = getChoiceCardsSettings(
113+
'UnitedStates',
114+
'Epic',
115+
mockProductCatalog,
116+
mockPromotionsCache,
117+
promoCodes,
118+
variantChoiceCardSettings,
119+
);
120+
121+
expect(result).toBeDefined();
122+
expect(result?.choiceCards[0].destinationUrl).toEqual(
123+
'https://support.theguardian.com/contribute/one-time',
124+
);
96125
});
97126

98127
it('returns choice cards with monthly discount (PROMO_B) applied', () => {

src/server/lib/choiceCards/choiceCards.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ const enrichChoiceCard = (
8383
benefitsLabel: choiceCard.benefitsLabel,
8484
benefits,
8585
pill,
86+
destinationUrl: choiceCard.destinationUrl, // Preserve the destination URL
8687
};
8788
};
8889

src/server/lib/choiceCards/defaultChoiceCardSettings.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const oneOffCard = (countryGroupId: CountryGroupId): ChoiceCard => ({
2020
: 'We welcome support of any size, any time',
2121
},
2222
],
23+
destinationUrl: null, // Will use default CTA behavior
2324
});
2425

2526
const fullChoiceCards = (countryGroupId: CountryGroupId): ChoiceCard[] => [
@@ -35,6 +36,7 @@ const fullChoiceCards = (countryGroupId: CountryGroupId): ChoiceCard[] => [
3536
copy: 'Give to the Guardian every month with Support',
3637
},
3738
],
39+
destinationUrl: null, // Will use default CTA behavior
3840
},
3941
{
4042
product: {
@@ -56,6 +58,7 @@ const fullChoiceCards = (countryGroupId: CountryGroupId): ChoiceCard[] => [
5658
pill: {
5759
copy: 'Recommended',
5860
},
61+
destinationUrl: null, // Will use default CTA behavior
5962
},
6063
oneOffCard(countryGroupId),
6164
];
@@ -88,6 +91,7 @@ const shorterChoiceCards = (countryGroupId: CountryGroupId): ChoiceCard[] => [
8891
pill: {
8992
copy: 'Recommended',
9093
},
94+
destinationUrl: null, // Will use default CTA behavior
9195
},
9296
oneOffCard(countryGroupId),
9397
];

src/shared/types/props/choiceCards.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const choiceCardSchema = z.object({
3636
benefitsLabel: z.string().nullish(), // e.g. "Unlock All-access digital benefits:"
3737
benefits: z.array(productBenefitSchema),
3838
pill: pillSchema.nullish(),
39+
destinationUrl: z.string().nullish(), // Optional override URL for this choice card
3940
});
4041

4142
export type ChoiceCard = z.infer<typeof choiceCardSchema>;

0 commit comments

Comments
 (0)