"use strict";
/**
 * vertical-group-bundle-licensing.test.ts
 *
 * Tests for the license-layer bundling helpers in vertical-group-catalog.ts.
 *
 * Thomas Layer 0 directive 2026-05-22 01:00 (clarification):
 *   "Include" = LICENSE the pack as bundled with the group purchase (free at
 *   the org level). "Assign to agent" = SEPARATE explicit action by staff/owner.
 *
 * These tests verify the licensing layer only — they do NOT test agent binding
 * or per-rule verification, which are explicit customer actions.
 *
 * Test IDs:
 *   BL-1   groupBundlesIso27001: returns true for every group
 *   BL-2   groupBundlesGdpr: returns true for EU / Global / International groups
 *   BL-3   groupBundlesGdpr: returns true for EU member state groups
 *   BL-4   groupBundlesGdpr: returns false for non-EU groups (US / UK / AU / CA)
 *   BL-5   bundledLicensedPacks: returns ['iso27001'] for non-EU groups
 *   BL-6   bundledLicensedPacks: returns ['iso27001', 'gdpr'] for EU groups
 *   BL-7   bundledLicensedPacks: filters out iso27001 when it is already a primary pack
 *   BL-8   bundledLicensedPacks: filters out gdpr when it is already a primary pack
 *   BL-9   computeVerticalGroups: every group has a non-empty includedBaselinePacks field
 *   BL-10  computeVerticalGroups: EU groups include 'gdpr' in includedBaselinePacks
 *
 * Step 5 RED→GREEN:
 *   RED  (before): groupBundlesIso27001 / groupBundlesGdpr / bundledLicensedPacks
 *                  did not exist in vertical-group-catalog.ts.
 *   GREEN (after): all BL 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");
// ---------------------------------------------------------------------------
// Helpers to build minimal VerticalGroup fixtures without touching the real DB
// ---------------------------------------------------------------------------
function makePack(id, jurisdiction) {
    return {
        id,
        name: id,
        shortName: id,
        description: '',
        jurisdiction,
        vertical: 'Healthcare',
        priority: 'P1',
        status: 'ACTIVE',
        frameworkCategory: 'sector-specific',
        keyRequirements: [],
        aiRelevance: '',
        crossIndustry: false,
        pricing: { tier: '6000', monthlyUsd: 500, annualUsd: 5100 },
    };
}
function makeGroup(jurisdiction, packIds = ['hipaa']) {
    const packs = packIds.map((id) => makePack(id, jurisdiction));
    // Build a base group without includedBaselinePacks first, then compute it.
    const base = {
        groupKey: `healthcare-${jurisdiction.toLowerCase().replace(/\s+/g, '-')}`,
        vertical: 'Healthcare',
        jurisdiction,
        displayName: `${jurisdiction} Healthcare`,
        description: '',
        packs,
        priceAnnualUsd: 4000,
    };
    return { ...base, includedBaselinePacks: (0, vertical_group_catalog_js_1.bundledLicensedPacks)(base) };
}
// ---------------------------------------------------------------------------
// BL-1: groupBundlesIso27001 always returns true
// ---------------------------------------------------------------------------
(0, node_test_1.describe)('BL-1: groupBundlesIso27001 always true', () => {
    (0, node_test_1.it)('returns true for a US group', () => {
        strict_1.default.equal((0, vertical_group_catalog_js_1.groupBundlesIso27001)(makeGroup('US')), true);
    });
    (0, node_test_1.it)('returns true for an EU group', () => {
        strict_1.default.equal((0, vertical_group_catalog_js_1.groupBundlesIso27001)(makeGroup('EU')), true);
    });
    (0, node_test_1.it)('returns true for a Global group', () => {
        strict_1.default.equal((0, vertical_group_catalog_js_1.groupBundlesIso27001)(makeGroup('Global')), true);
    });
    (0, node_test_1.it)('returns true for an AU group', () => {
        strict_1.default.equal((0, vertical_group_catalog_js_1.groupBundlesIso27001)(makeGroup('AU')), true);
    });
    (0, node_test_1.it)('returns true for every computed group in the registry', () => {
        const groups = (0, vertical_group_catalog_js_1.computeVerticalGroups)();
        for (const g of groups) {
            strict_1.default.equal((0, vertical_group_catalog_js_1.groupBundlesIso27001)(g), true);
        }
    });
});
// ---------------------------------------------------------------------------
// BL-2: groupBundlesGdpr — EU / Global / International
// ---------------------------------------------------------------------------
(0, node_test_1.describe)('BL-2: groupBundlesGdpr for EU / Global / International', () => {
    (0, node_test_1.it)('returns true for jurisdiction "EU"', () => {
        strict_1.default.equal((0, vertical_group_catalog_js_1.groupBundlesGdpr)(makeGroup('EU')), true);
    });
    (0, node_test_1.it)('returns true for jurisdiction "Global"', () => {
        strict_1.default.equal((0, vertical_group_catalog_js_1.groupBundlesGdpr)(makeGroup('Global')), true);
    });
    (0, node_test_1.it)('returns true for jurisdiction "International"', () => {
        strict_1.default.equal((0, vertical_group_catalog_js_1.groupBundlesGdpr)(makeGroup('International')), true);
    });
    (0, node_test_1.it)('returns true for a jurisdiction containing EU- prefix', () => {
        strict_1.default.equal((0, vertical_group_catalog_js_1.groupBundlesGdpr)(makeGroup('EU-MDR compliance zone')), true);
    });
});
// ---------------------------------------------------------------------------
// BL-3: groupBundlesGdpr — EU member states
// ---------------------------------------------------------------------------
(0, node_test_1.describe)('BL-3: groupBundlesGdpr for EU member states', () => {
    const memberStates = [
        'Germany',
        'France',
        'Italy',
        'Spain',
        'Netherlands',
        'Belgium',
        'Ireland',
        'Austria',
        'Sweden',
        'Denmark',
        'Finland',
        'Poland',
        'Czech Republic',
        'Portugal',
        'Greece',
        'Hungary',
        'Romania',
        'Bulgaria',
    ];
    for (const state of memberStates) {
        (0, node_test_1.it)(`returns true for jurisdiction "${state}"`, () => {
            strict_1.default.equal((0, vertical_group_catalog_js_1.groupBundlesGdpr)(makeGroup(state)), true);
        });
    }
});
// ---------------------------------------------------------------------------
// BL-4: groupBundlesGdpr — non-EU jurisdictions
// ---------------------------------------------------------------------------
(0, node_test_1.describe)('BL-4: groupBundlesGdpr returns false for non-EU jurisdictions', () => {
    (0, node_test_1.it)('returns false for US', () => {
        strict_1.default.equal((0, vertical_group_catalog_js_1.groupBundlesGdpr)(makeGroup('US')), false);
    });
    (0, node_test_1.it)('returns false for UK', () => {
        strict_1.default.equal((0, vertical_group_catalog_js_1.groupBundlesGdpr)(makeGroup('UK')), false);
    });
    (0, node_test_1.it)('returns false for AU', () => {
        strict_1.default.equal((0, vertical_group_catalog_js_1.groupBundlesGdpr)(makeGroup('AU')), false);
    });
    (0, node_test_1.it)('returns false for CA (Canada)', () => {
        strict_1.default.equal((0, vertical_group_catalog_js_1.groupBundlesGdpr)(makeGroup('CA')), false);
    });
    (0, node_test_1.it)('returns false for Singapore', () => {
        strict_1.default.equal((0, vertical_group_catalog_js_1.groupBundlesGdpr)(makeGroup('Singapore')), false);
    });
    (0, node_test_1.it)('returns false for Japan', () => {
        strict_1.default.equal((0, vertical_group_catalog_js_1.groupBundlesGdpr)(makeGroup('Japan')), false);
    });
});
// ---------------------------------------------------------------------------
// BL-5: bundledLicensedPacks — non-EU returns ['iso27001'] only
// ---------------------------------------------------------------------------
(0, node_test_1.describe)('BL-5: bundledLicensedPacks for non-EU groups', () => {
    (0, node_test_1.it)('returns ["iso27001"] for a US group', () => {
        strict_1.default.deepEqual((0, vertical_group_catalog_js_1.bundledLicensedPacks)(makeGroup('US')), ['iso27001']);
    });
    (0, node_test_1.it)('returns ["iso27001"] for a UK group', () => {
        strict_1.default.deepEqual((0, vertical_group_catalog_js_1.bundledLicensedPacks)(makeGroup('UK')), ['iso27001']);
    });
    (0, node_test_1.it)('returns ["iso27001"] for an AU group', () => {
        strict_1.default.deepEqual((0, vertical_group_catalog_js_1.bundledLicensedPacks)(makeGroup('AU')), ['iso27001']);
    });
});
// ---------------------------------------------------------------------------
// BL-6: bundledLicensedPacks — EU returns ['iso27001', 'gdpr']
// ---------------------------------------------------------------------------
(0, node_test_1.describe)('BL-6: bundledLicensedPacks for EU groups', () => {
    (0, node_test_1.it)('returns ["iso27001", "gdpr"] for an EU group', () => {
        strict_1.default.deepEqual((0, vertical_group_catalog_js_1.bundledLicensedPacks)(makeGroup('EU')), ['iso27001', 'gdpr']);
    });
    (0, node_test_1.it)('returns ["iso27001", "gdpr"] for a Global group', () => {
        strict_1.default.deepEqual((0, vertical_group_catalog_js_1.bundledLicensedPacks)(makeGroup('Global')), ['iso27001', 'gdpr']);
    });
    (0, node_test_1.it)('returns ["iso27001", "gdpr"] for a Germany group', () => {
        strict_1.default.deepEqual((0, vertical_group_catalog_js_1.bundledLicensedPacks)(makeGroup('Germany')), ['iso27001', 'gdpr']);
    });
    (0, node_test_1.it)('returns ["iso27001", "gdpr"] for a France group', () => {
        strict_1.default.deepEqual((0, vertical_group_catalog_js_1.bundledLicensedPacks)(makeGroup('France')), ['iso27001', 'gdpr']);
    });
});
// ---------------------------------------------------------------------------
// BL-7: bundledLicensedPacks — filters iso27001 when already primary
// ---------------------------------------------------------------------------
(0, node_test_1.describe)('BL-7: bundledLicensedPacks filters iso27001 when already primary', () => {
    (0, node_test_1.it)('excludes iso27001 from bundles when it is in group.packs', () => {
        const group = makeGroup('US', ['iso27001', 'soc2']);
        const result = (0, vertical_group_catalog_js_1.bundledLicensedPacks)(group);
        strict_1.default.equal(result.includes('iso27001'), false);
    });
    (0, node_test_1.it)('returns empty array for a US group whose primary IS iso27001', () => {
        const group = makeGroup('US', ['iso27001']);
        strict_1.default.deepEqual((0, vertical_group_catalog_js_1.bundledLicensedPacks)(group), []);
    });
});
// ---------------------------------------------------------------------------
// BL-8: bundledLicensedPacks — filters gdpr when already primary
// ---------------------------------------------------------------------------
(0, node_test_1.describe)('BL-8: bundledLicensedPacks filters gdpr when already primary', () => {
    (0, node_test_1.it)('excludes gdpr from bundles when it is in group.packs for an EU group', () => {
        const group = makeGroup('EU', ['gdpr', 'eu_ai_act']);
        const result = (0, vertical_group_catalog_js_1.bundledLicensedPacks)(group);
        strict_1.default.equal(result.includes('gdpr'), false);
    });
    (0, node_test_1.it)('still includes iso27001 even when gdpr is the primary pack', () => {
        const group = makeGroup('EU', ['gdpr']);
        strict_1.default.equal((0, vertical_group_catalog_js_1.bundledLicensedPacks)(group).includes('iso27001'), true);
    });
});
// ---------------------------------------------------------------------------
// BL-9: computeVerticalGroups — every group has includedBaselinePacks array
// ---------------------------------------------------------------------------
(0, node_test_1.describe)('BL-9: computeVerticalGroups includes baseline packs', () => {
    (0, node_test_1.it)('every group has an includedBaselinePacks array', () => {
        const groups = (0, vertical_group_catalog_js_1.computeVerticalGroups)();
        strict_1.default.ok(groups.length > 0);
        for (const g of groups) {
            strict_1.default.ok(Array.isArray(g.includedBaselinePacks), `Group ${g.groupKey} missing includedBaselinePacks`);
        }
    });
    (0, node_test_1.it)('groups whose primary packs do NOT include iso27001 have it in includedBaselinePacks', () => {
        const groups = (0, vertical_group_catalog_js_1.computeVerticalGroups)();
        const withoutIso = groups.filter((g) => !g.packs.some((p) => p.id === 'iso27001'));
        for (const g of withoutIso) {
            strict_1.default.equal(g.includedBaselinePacks.includes('iso27001'), true, `Group ${g.groupKey} (jurisdiction: ${g.jurisdiction}) is missing iso27001 in includedBaselinePacks`);
        }
    });
});
// ---------------------------------------------------------------------------
// BL-10: computeVerticalGroups — EU groups include 'gdpr' in includedBaselinePacks
// ---------------------------------------------------------------------------
(0, node_test_1.describe)('BL-10: computeVerticalGroups EU groups include gdpr', () => {
    (0, node_test_1.it)('EU / Global / International groups include gdpr (when not already primary)', () => {
        const groups = (0, vertical_group_catalog_js_1.computeVerticalGroups)();
        const euGroups = groups.filter((g) => g.jurisdiction.toLowerCase().includes('eu') ||
            g.jurisdiction.toLowerCase().includes('global') ||
            g.jurisdiction.toLowerCase().includes('international'));
        for (const g of euGroups) {
            const gdprIsPrimary = g.packs.some((p) => p.id === 'gdpr');
            if (!gdprIsPrimary) {
                strict_1.default.equal(g.includedBaselinePacks.includes('gdpr'), true, `EU group ${g.groupKey} missing gdpr in includedBaselinePacks`);
            }
        }
    });
});
//# sourceMappingURL=vertical-group-bundle-licensing.test.js.map