v4.0.0.4 - Pricing changes

This commit is contained in:
2026-05-31 07:37:29 +12:00
parent 91b22c6d60
commit 7d5b72e1d3
5 changed files with 5 additions and 10 deletions
+3 -3
View File
@@ -3,17 +3,17 @@ import { describe, expect, it } from 'vitest';
import { decoratePlans } from './pricing';
describe('decoratePlans', () => {
it('prefers an explicit popular plan over the cheapest plan', () => {
it('always highlights the cheapest plan, ignoring any popular flag', () => {
const plans = decoratePlans([
{ title: 'Cheapest', price: '$39', period: 'Per Walk' },
{ title: 'Recommended', price: '$49', period: 'Per Walk', popular: true },
{ title: 'Longest', price: '$55', period: 'Per Walk' }
]);
expect(plans.map((plan) => plan.isPopular)).toEqual([false, true, false]);
expect(plans.map((plan) => plan.isPopular)).toEqual([true, false, false]);
});
it('falls back to the cheapest plan when none is marked popular', () => {
it('highlights the cheapest plan regardless of order', () => {
const plans = decoratePlans([
{ title: 'Weekly', price: '$58', period: 'Per Walk' },
{ title: 'Regular', price: '$55', period: 'Per Walk' },
+2 -4
View File
@@ -11,10 +11,8 @@ export function decoratePlans<T extends { price: string; period: string }>(plans
}));
const sorted = [...enriched].sort((a, b) => a.value - b.value || a.index - b.index);
const explicitPopularIndex = plans.findIndex(
(plan) => 'popular' in plan && Boolean((plan as T & { popular?: boolean }).popular)
);
const featuredIndex = explicitPopularIndex >= 0 ? explicitPopularIndex : (sorted[0]?.index ?? -1);
// The cheapest plan is always the highlighted one, on desktop and mobile.
const featuredIndex = sorted[0]?.index ?? -1;
const mobileOrder = new Map(sorted.map((entry, order) => [entry.index, order]));
return plans.map((plan, index) => ({