fix(catalog): keep Complete Packs last and omit redundant pack row for single-module NUTRITION_CORE
This commit is contained in:
parent
d5fa9ad00d
commit
2013659a20
|
|
@ -137,18 +137,20 @@ export function buildDynamicCatalog(
|
|||
planType: plan.plan_type,
|
||||
});
|
||||
}
|
||||
items.push({
|
||||
code,
|
||||
name: cfg.packTitle,
|
||||
category: cfg.category,
|
||||
priceInr,
|
||||
priceUsd,
|
||||
priceEur,
|
||||
desc: planDesc || primaryFallback?.desc || `Unlock all ${cfg.category} modules.`,
|
||||
color: cfg.defaultColor,
|
||||
sortOrder: 9999,
|
||||
planType: plan.plan_type,
|
||||
});
|
||||
if (planModules.length > 1) {
|
||||
items.push({
|
||||
code,
|
||||
name: cfg.packTitle,
|
||||
category: cfg.category,
|
||||
priceInr,
|
||||
priceUsd,
|
||||
priceEur,
|
||||
desc: planDesc || primaryFallback?.desc || `Unlock all ${cfg.category} modules.`,
|
||||
color: cfg.defaultColor,
|
||||
sortOrder: Number.MAX_SAFE_INTEGER,
|
||||
planType: plan.plan_type,
|
||||
});
|
||||
}
|
||||
} else if (fallbackEntries.length > 0) {
|
||||
for (const fb of fallbackEntries) {
|
||||
items.push({
|
||||
|
|
@ -156,7 +158,7 @@ export function buildDynamicCatalog(
|
|||
priceInr,
|
||||
priceUsd,
|
||||
priceEur,
|
||||
sortOrder: fb.name.includes('Complete Pack') ? 9999 : 500,
|
||||
sortOrder: fb.name.includes('Complete Pack') ? Number.MAX_SAFE_INTEGER : 500,
|
||||
planType: plan.plan_type,
|
||||
});
|
||||
}
|
||||
|
|
@ -176,7 +178,7 @@ export function buildDynamicCatalog(
|
|||
priceEur,
|
||||
desc: planDesc,
|
||||
color: planColor,
|
||||
sortOrder: 9999,
|
||||
sortOrder: Number.MAX_SAFE_INTEGER,
|
||||
planType: plan.plan_type,
|
||||
});
|
||||
continue;
|
||||
|
|
|
|||
|
|
@ -72,7 +72,51 @@ describe('buildDynamicCatalog', () => {
|
|||
'Zang-Fu Organs',
|
||||
'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', () => {
|
||||
|
|
|
|||
Loading…
Reference in New Issue