const fs = require('fs');
const path = require('path');

const sql = fs.readFileSync(path.join(__dirname, '..', 'install', 'database_installer.sql'), 'utf8');
const catalog = fs.readFileSync(path.join(__dirname, '..', 'install', 'special_tests_catalog.php'), 'utf8');

const excludedNames = [
    'Complete Blood Count (CBC)',
    'CBC (Complete Blood Count)',
    'Urine Complete Examination',
    'Lipid Profile',
    'Fasting Lipid Profile (FLP)',
    'Liver Function Test (LFT)',
    'LFTs (Liver Function Test)',
    'Renal Function Test (RFTs)',
    'TSH (Thyroid Stimulating Hormone)',
];

describe('Installer core panel exclusions', () => {
    test('includes a final deactivation block for excluded tests', () => {
        expect(sql).toContain('INSTALLER EXCLUSION');
        expect(sql).toContain("report_template='Without normal range - Saima Labs'").toBeFalsy();
    });

    test('does not seed canonical CBC/LFT/Lipid/RFT/Urine/TSH replacement blocks', () => {
        expect(sql).not.toContain("SELECT '0025','Liver Function Test (LFT)'");
        expect(sql).not.toContain("SELECT '0046','Renal Function Test (RFTs)'");
        expect(sql).not.toContain("SELECT 'CBC','CBC (Complete Blood Count)'");
        expect(sql).not.toContain("test_code='1118',name='Urine Complete Examination'");
        expect(sql).not.toContain("test_code='0333',name='TSH (Thyroid Stimulating Hormone)'");
        expect(sql).not.toContain("SELECT 'Fasting Lipid Profile (FLP)'");
    });

    test('marks removed sections with exclusion comments', () => {
        expect(sql).toContain('CBC excluded from installer');
        expect(sql).toContain('Urine C/E excluded from installer');
        expect(sql).toContain('LFT excluded from installer');
        expect(sql).toContain('Lipid Profile excluded from installer');
        expect(sql).toContain('RFT excluded from installer');
        expect(sql).toContain('Standalone TSH excluded from installer');
    });

    test('skips ST001 TSH in special tests catalogue', () => {
        expect(catalog).toContain("if ($code === 'ST001')");
        expect(catalog).toContain('continue;');
    });
});
