"use strict";
/**
 * vertical-group-catalog.test.ts
 *
 * Tests for the vertical group catalog computation and pricing tier logic.
 *
 * Thomas Layer 0 directive 2026-05-22 00:10:
 *   - Group pricing: 4 packs=$4k, 5=$5k, 6=$6k, 7+=$7k
 *   - All 143 active packs must be assigned to a group (no orphans)
 *   - No pack appears in more than one group (no duplicates)
 *
 * Test IDs:
 *   G-1   priceForGroupSize: boundary values
 *   G-2   priceForGroupSize: 7+ always caps at $7,000
 *   G-3   computeVerticalGroups: returns at least one group
 *   G-4   computeVerticalGroups: all ACTIVE_PACKS appear in exactly one group
 *   G-5   computeVerticalGroups: no duplicate pack IDs across groups
 *   G-6   computeVerticalGroups: every group has priceAnnualUsd matching priceForGroupSize(count)
 *   G-7   computeVerticalGroups: sorted descending by pack count
 *   G-8   computeVerticalGroups: groupKey is a stable lowercase slug (no spaces/special chars)
 *   G-9   findGroupForPack: returns correct group for a known packId
 *   G-10  findGroupForPack: returns null for an unknown packId
 *   G-11  BILLING_CAP_USD = 7000, ADDON_PRICE_ANNUAL_USD = 400
 *
 * Step 5 RED→GREEN:
 *   RED  (before): vertical-group-catalog.ts did not exist.
 *   GREEN (after): all 11 tests pass.
 */
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const node_test_1 = require("node:test");
const strict_1 = __importDefault(require("node:assert/strict"));
const vertical_group_catalog_js_1 = require("../vertical-group-catalog.js");
// ---------------------------------------------------------------------------
// G-11: Constants
// ---------------------------------------------------------------------------
(0, node_test_1.describe)('Constants', () => {
    (0, node_test_1.it)('G-11: BILLING_CAP_USD is $7,000 and ADDON_PRICE_ANNUAL_USD is $400', () => {
        strict_1.default.equal(vertical_group_catalog_js_1.BILLING_CAP_USD, 7_000);
        strict_1.default.equal(vertical_group_catalog_js_1.ADDON_PRICE_ANNUAL_USD, 400);
    });
});
// ---------------------------------------------------------------------------
// G-1, G-2: priceForGroupSize
// ---------------------------------------------------------------------------
(0, node_test_1.describe)('priceForGroupSize()', () => {
    (0, node_test_1.it)('G-1: boundary values — 1, 2, 3 packs return linear $1k/pack', () => {
        strict_1.default.equal((0, vertical_group_catalog_js_1.priceForGroupSize)(1), 1_000);
        strict_1.default.equal((0, vertical_group_catalog_js_1.priceForGroupSize)(2), 2_000);
        strict_1.default.equal((0, vertical_group_catalog_js_1.priceForGroupSize)(3), 3_000);
    });
    (0, node_test_1.it)('G-1: 4 packs → $4,000', () => {
        strict_1.default.equal((0, vertical_group_catalog_js_1.priceForGroupSize)(4), 4_000);
    });
    (0, node_test_1.it)('G-1: 5 packs → $5,000', () => {
        strict_1.default.equal((0, vertical_group_catalog_js_1.priceForGroupSize)(5), 5_000);
    });
    (0, node_test_1.it)('G-1: 6 packs → $6,000', () => {
        strict_1.default.equal((0, vertical_group_catalog_js_1.priceForGroupSize)(6), 6_000);
    });
    (0, node_test_1.it)('G-2: 7 packs → $7,000 (cap)', () => {
        strict_1.default.equal((0, vertical_group_catalog_js_1.priceForGroupSize)(7), 7_000);
    });
    (0, node_test_1.it)('G-2: 10 packs → $7,000 (auto-cap, not $10,000)', () => {
        strict_1.default.equal((0, vertical_group_catalog_js_1.priceForGroupSize)(10), 7_000);
    });
    (0, node_test_1.it)('G-2: 100 packs → $7,000 (auto-cap)', () => {
        strict_1.default.equal((0, vertical_group_catalog_js_1.priceForGroupSize)(100), 7_000);
    });
    (0, node_test_1.it)('G-1: 0 packs → $0 (edge case)', () => {
        strict_1.default.equal((0, vertical_group_catalog_js_1.priceForGroupSize)(0), 0);
    });
});
// ---------------------------------------------------------------------------
// G-3 through G-8: computeVerticalGroups
// ---------------------------------------------------------------------------
(0, node_test_1.describe)('computeVerticalGroups()', () => {
    const groups = (0, vertical_group_catalog_js_1.computeVerticalGroups)();
    (0, node_test_1.it)('G-3: returns at least one group', () => {
        strict_1.default.ok(groups.length >= 1, `Expected at least 1 group, got ${groups.length}`);
    });
    (0, node_test_1.it)('G-4: all ACTIVE_PACKS appear in exactly one group', () => {
        // Collect all pack IDs from all groups
        const allPackIdsInGroups = groups.flatMap((g) => g.packs.map((p) => p.id));
        const activePackIds = vertical_group_catalog_js_1.ACTIVE_PACKS.map((p) => p.id);
        // Every active pack must appear in a group
        for (const id of activePackIds) {
            strict_1.default.ok(allPackIdsInGroups.includes(id), `Active pack "${id}" is not assigned to any group`);
        }
        // Total pack count must equal ACTIVE_PACKS.length (no orphans, no duplication)
        strict_1.default.equal(allPackIdsInGroups.length, activePackIds.length, `Total packs in groups (${allPackIdsInGroups.length}) != ACTIVE_PACKS count (${activePackIds.length})`);
    });
    (0, node_test_1.it)('G-5: no duplicate pack IDs across groups', () => {
        const allPackIds = groups.flatMap((g) => g.packs.map((p) => p.id));
        const unique = new Set(allPackIds);
        strict_1.default.equal(allPackIds.length, unique.size, `Duplicate pack IDs detected: ${allPackIds.length} total, ${unique.size} unique`);
    });
    (0, node_test_1.it)('G-6: every group priceAnnualUsd matches priceForGroupSize(packCount)', () => {
        for (const group of groups) {
            const expected = (0, vertical_group_catalog_js_1.priceForGroupSize)(group.packs.length);
            strict_1.default.equal(group.priceAnnualUsd, expected, `Group "${group.groupKey}" has priceAnnualUsd=${group.priceAnnualUsd} but expected ${expected} for ${group.packs.length} packs`);
        }
    });
    (0, node_test_1.it)('G-7: groups are sorted descending by pack count', () => {
        for (let i = 1; i < groups.length; i++) {
            strict_1.default.ok(groups[i - 1].packs.length >= groups[i].packs.length, `Groups not sorted at index ${i}: ${groups[i - 1].packs.length} < ${groups[i].packs.length}`);
        }
    });
    (0, node_test_1.it)('G-8: groupKey is a stable lowercase slug with no spaces or special chars', () => {
        for (const group of groups) {
            strict_1.default.match(group.groupKey, /^[a-z0-9-]+$/, `groupKey "${group.groupKey}" contains invalid characters`);
        }
    });
    (0, node_test_1.it)('G-8: groupKeys are unique', () => {
        const keys = groups.map((g) => g.groupKey);
        const unique = new Set(keys);
        strict_1.default.equal(keys.length, unique.size, 'Duplicate groupKeys detected');
    });
});
// ---------------------------------------------------------------------------
// G-9, G-10: findGroupForPack
// ---------------------------------------------------------------------------
(0, node_test_1.describe)('findGroupForPack()', () => {
    (0, node_test_1.it)('G-9: returns the correct group for a known packId (hipaa)', () => {
        const group = (0, vertical_group_catalog_js_1.findGroupForPack)('hipaa');
        strict_1.default.ok(group !== null, 'Expected a group for "hipaa", got null');
        strict_1.default.ok(group.packs.some((p) => p.id === 'hipaa'), `Group "${group.groupKey}" does not contain hipaa pack`);
        // HIPAA is in Healthcare/US — group key should contain those slugs
        strict_1.default.ok(group.groupKey.includes('healthcare') || group.groupKey.includes('us'), `Expected hipaa group key to contain "healthcare" or "us", got "${group.groupKey}"`);
    });
    (0, node_test_1.it)('G-9: returns the correct group for a known packId (gdpr)', () => {
        const group = (0, vertical_group_catalog_js_1.findGroupForPack)('gdpr');
        strict_1.default.ok(group !== null, 'Expected a group for "gdpr", got null');
        strict_1.default.ok(group.packs.some((p) => p.id === 'gdpr'), `Group "${group.groupKey}" does not contain gdpr pack`);
    });
    (0, node_test_1.it)('G-10: returns null for an unknown packId', () => {
        const group = (0, vertical_group_catalog_js_1.findGroupForPack)('DOES_NOT_EXIST_XYZ_2026');
        strict_1.default.equal(group, null);
    });
    (0, node_test_1.it)('G-9: uses pre-computed groups when provided', () => {
        const groups = (0, vertical_group_catalog_js_1.computeVerticalGroups)();
        const groupFromFull = (0, vertical_group_catalog_js_1.findGroupForPack)('hipaa', groups);
        strict_1.default.ok(groupFromFull !== null, 'Expected a group when catalog is pre-computed');
    });
});
//# sourceMappingURL=vertical-group-catalog.test.js.map