acupedia-store-ui/tests/unit/catalog.test.ts

101 lines
3.0 KiB
TypeScript

import { describe, it, expect } from 'vitest';
import { buildDynamicCatalog, resolvePlanCategory } from '../../src/utils/catalog';
import { CURRICULUM_MODULES } from '../../src/constants/modules';
import type { PublicPlan } from '../../src/types';
describe('buildDynamicCatalog', () => {
it('falls back to CURRICULUM_MODULES when publicPlans is empty', () => {
const result = buildDynamicCatalog([]);
expect(result).toEqual(CURRICULUM_MODULES);
});
it('maps newly created Module Builder one_time plan to its normalized category with sortOrder', () => {
const plans: PublicPlan[] = [
{
code: 'MOD_M0044',
base_code: 'MOD_M0044',
name: 'Pediatric Disorders',
description: 'TCM pediatric treatment protocols.',
plan_type: 'one_time',
price_inr: 600,
price_usd: 15,
price_eur: 15,
is_active: true,
modules: [
{
id: 'mod-44',
code: 'm0044',
slug: 'pediatric-disorders',
name: 'Pediatric Disorders',
description: 'TCM pediatric treatment protocols.',
category: 'Therapeutics',
sort_order: 40,
},
],
},
];
const result = buildDynamicCatalog(plans);
expect(result).toHaveLength(1);
expect(result[0]).toMatchObject({
code: 'MOD_M0044',
name: 'Pediatric Disorders',
category: 'Therapeutics',
priceInr: 600,
priceUsd: 15,
priceEur: 15,
sortOrder: 40,
});
});
it('expands PATTERN_CORE sub-modules from plan.modules and appends Complete Pack', () => {
const plans: PublicPlan[] = [
{
code: 'PATTERN_CORE',
name: 'Pattern: Complete Pack',
description: 'All pattern methodologies.',
plan_type: 'bundle',
price_inr: 500,
price_usd: 10,
price_eur: 10,
is_active: true,
modules: [
{ name: 'Zang-Fu Organs', slug: 'zang-fu', category: 'Pattern', sort_order: 2 },
{ name: 'Eight Principles', slug: 'eight-principles', category: 'Pattern', sort_order: 1 },
],
},
];
const result = buildDynamicCatalog(plans);
expect(result.map((m) => m.name)).toEqual([
'Eight Principles',
'Zang-Fu Organs',
'Pattern: Complete Pack',
]);
expect(result[2].sortOrder).toBe(9999);
});
it('resolves non-standard category or custom bundle cleanly', () => {
const unknownCatPlan: PublicPlan = {
code: 'MOD_HERB',
name: 'Herbal Formulas',
plan_type: 'one_time',
is_active: true,
modules: [{ name: 'Herbal Formulas', category: 'Herbalism', sort_order: 50 }],
};
expect(resolvePlanCategory(unknownCatPlan)).toBe('Herbalism');
const bundlePlan: PublicPlan = {
code: 'STARTER_BUNDLE',
name: 'Starter Bundle',
plan_type: 'bundle',
price_inr: 1200,
price_usd: 25,
price_eur: 25,
is_active: true,
};
const result = buildDynamicCatalog([bundlePlan]);
expect(result[0].category).toBe('Bundle');
});
});