feat/dynamic-storefront-catalog #124
|
|
@ -137,18 +137,20 @@ export function buildDynamicCatalog(
|
||||||
planType: plan.plan_type,
|
planType: plan.plan_type,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
items.push({
|
if (planModules.length > 1) {
|
||||||
code,
|
items.push({
|
||||||
name: cfg.packTitle,
|
code,
|
||||||
category: cfg.category,
|
name: cfg.packTitle,
|
||||||
priceInr,
|
category: cfg.category,
|
||||||
priceUsd,
|
priceInr,
|
||||||
priceEur,
|
priceUsd,
|
||||||
desc: planDesc || primaryFallback?.desc || `Unlock all ${cfg.category} modules.`,
|
priceEur,
|
||||||
color: cfg.defaultColor,
|
desc: planDesc || primaryFallback?.desc || `Unlock all ${cfg.category} modules.`,
|
||||||
sortOrder: 9999,
|
color: cfg.defaultColor,
|
||||||
planType: plan.plan_type,
|
sortOrder: Number.MAX_SAFE_INTEGER,
|
||||||
});
|
planType: plan.plan_type,
|
||||||
|
});
|
||||||
|
}
|
||||||
} else if (fallbackEntries.length > 0) {
|
} else if (fallbackEntries.length > 0) {
|
||||||
for (const fb of fallbackEntries) {
|
for (const fb of fallbackEntries) {
|
||||||
items.push({
|
items.push({
|
||||||
|
|
@ -156,7 +158,7 @@ export function buildDynamicCatalog(
|
||||||
priceInr,
|
priceInr,
|
||||||
priceUsd,
|
priceUsd,
|
||||||
priceEur,
|
priceEur,
|
||||||
sortOrder: fb.name.includes('Complete Pack') ? 9999 : 500,
|
sortOrder: fb.name.includes('Complete Pack') ? Number.MAX_SAFE_INTEGER : 500,
|
||||||
planType: plan.plan_type,
|
planType: plan.plan_type,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -176,7 +178,7 @@ export function buildDynamicCatalog(
|
||||||
priceEur,
|
priceEur,
|
||||||
desc: planDesc,
|
desc: planDesc,
|
||||||
color: planColor,
|
color: planColor,
|
||||||
sortOrder: 9999,
|
sortOrder: Number.MAX_SAFE_INTEGER,
|
||||||
planType: plan.plan_type,
|
planType: plan.plan_type,
|
||||||
});
|
});
|
||||||
continue;
|
continue;
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,51 @@ describe('buildDynamicCatalog', () => {
|
||||||
'Zang-Fu Organs',
|
'Zang-Fu Organs',
|
||||||
'Pattern: Complete Pack',
|
'Pattern: Complete Pack',
|
||||||
]);
|
]);
|
||||||
expect(result[2].sortOrder).toBe(9999);
|
expect(result[2].sortOrder).toBe(Number.MAX_SAFE_INTEGER);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('omits Complete Pack row for NUTRITION_CORE when only 1 module exists and keeps POINTS_PACK last', () => {
|
||||||
|
const plans: PublicPlan[] = [
|
||||||
|
{
|
||||||
|
code: 'NUTRITION_CORE',
|
||||||
|
name: 'Nutrition Module Access (1 Yr)',
|
||||||
|
plan_type: 'one_time',
|
||||||
|
price_inr: 600,
|
||||||
|
price_usd: 15,
|
||||||
|
price_eur: 15,
|
||||||
|
is_active: true,
|
||||||
|
modules: [{ code: 'm0031', name: 'Nutrition', slug: 'nutrition', category: 'Nutrition', sort_order: 99999 }],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
code: 'POINTS_PACK',
|
||||||
|
name: 'Points Complete Pack (1 Yr)',
|
||||||
|
plan_type: 'bundle',
|
||||||
|
price_inr: 900,
|
||||||
|
price_usd: 15,
|
||||||
|
price_eur: 15,
|
||||||
|
is_active: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
code: 'POINTS_ACU',
|
||||||
|
name: 'Acu Points Module (1 Yr)',
|
||||||
|
plan_type: 'one_time',
|
||||||
|
price_inr: 300,
|
||||||
|
price_usd: 5,
|
||||||
|
price_eur: 5,
|
||||||
|
is_active: true,
|
||||||
|
modules: [{ code: 'm0001', name: 'Acupuncture Points', slug: 'acupuncture-points', category: 'Points', sort_order: 99999 }],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const result = buildDynamicCatalog(plans);
|
||||||
|
const nutritionItems = result.filter((m) => m.category === 'Nutrition');
|
||||||
|
expect(nutritionItems).toHaveLength(1);
|
||||||
|
expect(nutritionItems[0].name).toBe('Nutrition');
|
||||||
|
|
||||||
|
const pointsItems = result
|
||||||
|
.filter((m) => m.category === 'Points')
|
||||||
|
.sort((a, b) => (a.sortOrder ?? 500) - (b.sortOrder ?? 500));
|
||||||
|
expect(pointsItems.map((m) => m.code)).toEqual(['POINTS_ACU', 'POINTS_PACK']);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('resolves non-standard category or custom bundle cleanly', () => {
|
it('resolves non-standard category or custom bundle cleanly', () => {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue