/**
 * 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.
 */
import { describe, it } from 'node:test';
import assert from 'node:assert/strict';
import { groupBundlesIso27001, groupBundlesGdpr, bundledLicensedPacks, computeVerticalGroups, } from '../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: bundledLicensedPacks(base) };
}
// ---------------------------------------------------------------------------
// BL-1: groupBundlesIso27001 always returns true
// ---------------------------------------------------------------------------
describe('BL-1: groupBundlesIso27001 always true', () => {
    it('returns true for a US group', () => {
        assert.equal(groupBundlesIso27001(makeGroup('US')), true);
    });
    it('returns true for an EU group', () => {
        assert.equal(groupBundlesIso27001(makeGroup('EU')), true);
    });
    it('returns true for a Global group', () => {
        assert.equal(groupBundlesIso27001(makeGroup('Global')), true);
    });
    it('returns true for an AU group', () => {
        assert.equal(groupBundlesIso27001(makeGroup('AU')), true);
    });
    it('returns true for every computed group in the registry', () => {
        const groups = computeVerticalGroups();
        for (const g of groups) {
            assert.equal(groupBundlesIso27001(g), true);
        }
    });
});
// ---------------------------------------------------------------------------
// BL-2: groupBundlesGdpr — EU / Global / International
// ---------------------------------------------------------------------------
describe('BL-2: groupBundlesGdpr for EU / Global / International', () => {
    it('returns true for jurisdiction "EU"', () => {
        assert.equal(groupBundlesGdpr(makeGroup('EU')), true);
    });
    it('returns true for jurisdiction "Global"', () => {
        assert.equal(groupBundlesGdpr(makeGroup('Global')), true);
    });
    it('returns true for jurisdiction "International"', () => {
        assert.equal(groupBundlesGdpr(makeGroup('International')), true);
    });
    it('returns true for a jurisdiction containing EU- prefix', () => {
        assert.equal(groupBundlesGdpr(makeGroup('EU-MDR compliance zone')), true);
    });
});
// ---------------------------------------------------------------------------
// BL-3: groupBundlesGdpr — EU member states
// ---------------------------------------------------------------------------
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) {
        it(`returns true for jurisdiction "${state}"`, () => {
            assert.equal(groupBundlesGdpr(makeGroup(state)), true);
        });
    }
});
// ---------------------------------------------------------------------------
// BL-4: groupBundlesGdpr — non-EU jurisdictions
// ---------------------------------------------------------------------------
describe('BL-4: groupBundlesGdpr returns false for non-EU jurisdictions', () => {
    it('returns false for US', () => {
        assert.equal(groupBundlesGdpr(makeGroup('US')), false);
    });
    it('returns false for UK', () => {
        assert.equal(groupBundlesGdpr(makeGroup('UK')), false);
    });
    it('returns false for AU', () => {
        assert.equal(groupBundlesGdpr(makeGroup('AU')), false);
    });
    it('returns false for CA (Canada)', () => {
        assert.equal(groupBundlesGdpr(makeGroup('CA')), false);
    });
    it('returns false for Singapore', () => {
        assert.equal(groupBundlesGdpr(makeGroup('Singapore')), false);
    });
    it('returns false for Japan', () => {
        assert.equal(groupBundlesGdpr(makeGroup('Japan')), false);
    });
});
// ---------------------------------------------------------------------------
// BL-5: bundledLicensedPacks — non-EU returns ['iso27001'] only
// ---------------------------------------------------------------------------
describe('BL-5: bundledLicensedPacks for non-EU groups', () => {
    it('returns ["iso27001"] for a US group', () => {
        assert.deepEqual(bundledLicensedPacks(makeGroup('US')), ['iso27001']);
    });
    it('returns ["iso27001"] for a UK group', () => {
        assert.deepEqual(bundledLicensedPacks(makeGroup('UK')), ['iso27001']);
    });
    it('returns ["iso27001"] for an AU group', () => {
        assert.deepEqual(bundledLicensedPacks(makeGroup('AU')), ['iso27001']);
    });
});
// ---------------------------------------------------------------------------
// BL-6: bundledLicensedPacks — EU returns ['iso27001', 'gdpr']
// ---------------------------------------------------------------------------
describe('BL-6: bundledLicensedPacks for EU groups', () => {
    it('returns ["iso27001", "gdpr"] for an EU group', () => {
        assert.deepEqual(bundledLicensedPacks(makeGroup('EU')), ['iso27001', 'gdpr']);
    });
    it('returns ["iso27001", "gdpr"] for a Global group', () => {
        assert.deepEqual(bundledLicensedPacks(makeGroup('Global')), ['iso27001', 'gdpr']);
    });
    it('returns ["iso27001", "gdpr"] for a Germany group', () => {
        assert.deepEqual(bundledLicensedPacks(makeGroup('Germany')), ['iso27001', 'gdpr']);
    });
    it('returns ["iso27001", "gdpr"] for a France group', () => {
        assert.deepEqual(bundledLicensedPacks(makeGroup('France')), ['iso27001', 'gdpr']);
    });
});
// ---------------------------------------------------------------------------
// BL-7: bundledLicensedPacks — filters iso27001 when already primary
// ---------------------------------------------------------------------------
describe('BL-7: bundledLicensedPacks filters iso27001 when already primary', () => {
    it('excludes iso27001 from bundles when it is in group.packs', () => {
        const group = makeGroup('US', ['iso27001', 'soc2']);
        const result = bundledLicensedPacks(group);
        assert.equal(result.includes('iso27001'), false);
    });
    it('returns empty array for a US group whose primary IS iso27001', () => {
        const group = makeGroup('US', ['iso27001']);
        assert.deepEqual(bundledLicensedPacks(group), []);
    });
});
// ---------------------------------------------------------------------------
// BL-8: bundledLicensedPacks — filters gdpr when already primary
// ---------------------------------------------------------------------------
describe('BL-8: bundledLicensedPacks filters gdpr when already primary', () => {
    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 = bundledLicensedPacks(group);
        assert.equal(result.includes('gdpr'), false);
    });
    it('still includes iso27001 even when gdpr is the primary pack', () => {
        const group = makeGroup('EU', ['gdpr']);
        assert.equal(bundledLicensedPacks(group).includes('iso27001'), true);
    });
});
// ---------------------------------------------------------------------------
// BL-9: computeVerticalGroups — every group has includedBaselinePacks array
// ---------------------------------------------------------------------------
describe('BL-9: computeVerticalGroups includes baseline packs', () => {
    it('every group has an includedBaselinePacks array', () => {
        const groups = computeVerticalGroups();
        assert.ok(groups.length > 0);
        for (const g of groups) {
            assert.ok(Array.isArray(g.includedBaselinePacks), `Group ${g.groupKey} missing includedBaselinePacks`);
        }
    });
    it('groups whose primary packs do NOT include iso27001 have it in includedBaselinePacks', () => {
        const groups = computeVerticalGroups();
        const withoutIso = groups.filter((g) => !g.packs.some((p) => p.id === 'iso27001'));
        for (const g of withoutIso) {
            assert.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
// ---------------------------------------------------------------------------
describe('BL-10: computeVerticalGroups EU groups include gdpr', () => {
    it('EU / Global / International groups include gdpr (when not already primary)', () => {
        const groups = 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) {
                assert.equal(g.includedBaselinePacks.includes('gdpr'), true, `EU group ${g.groupKey} missing gdpr in includedBaselinePacks`);
            }
        }
    });
});
//# sourceMappingURL=vertical-group-bundle-licensing.test.js.map