"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const privacy_manager_1 = require("../../walls/05-community/privacy/privacy-manager");
describe('PrivacyManager', () => {
    let pm;
    beforeEach(() => {
        pm = new privacy_manager_1.PrivacyManager();
        pm.setMode('private');
    });
    test('default mode is private', () => {
        const fresh = new privacy_manager_1.PrivacyManager();
        expect(fresh.getMode()).toBe('private');
    });
    test('setMode changes mode', () => {
        expect(pm.setMode('community')).toBe('community');
        expect(pm.getMode()).toBe('community');
        expect(pm.setMode('organization')).toBe('organization');
        expect(pm.getMode()).toBe('organization');
        expect(pm.setMode('private')).toBe('private');
        expect(pm.getMode()).toBe('private');
    });
    test('getSharingPreview returns valid payload', () => {
        const preview = pm.getSharingPreview();
        expect(preview.language).toBe('typescript');
        expect(preview.outcome).toBe('success');
        expect(preview.confidence).toBeGreaterThan(0);
    });
    test('isBlocked catches forbidden fields', () => {
        expect(pm.isBlocked('source_code')).toBe(true);
        expect(pm.isBlocked('file_path')).toBe(true);
        expect(pm.isBlocked('prompt')).toBe(true);
        expect(pm.isBlocked('secret')).toBe(true);
        expect(pm.isBlocked('api_key')).toBe(true);
        expect(pm.isBlocked('pii')).toBe(true);
        expect(pm.isBlocked('company_name')).toBe(true);
    });
    test('isBlocked allows safe fields', () => {
        expect(pm.isBlocked('language')).toBe(false);
        expect(pm.isBlocked('framework')).toBe(false);
        expect(pm.isBlocked('outcome')).toBe(false);
        expect(pm.isBlocked('confidence')).toBe(false);
        expect(pm.isBlocked('workflow')).toBe(false);
    });
    test('validatePayload blocks forbidden fields', () => {
        const result = pm.validatePayload({
            source_code: 'const x = 1',
            language: 'typescript',
        });
        expect(result.valid).toBe(false);
        expect(result.blockedFields).toContain('source_code');
    });
    test('validatePayload allows clean payload in community mode', () => {
        pm.setMode('community');
        const result = pm.validatePayload({
            language: 'typescript',
            framework: 'express',
            outcome: 'success',
            confidence: 0.94,
        });
        expect(result.valid).toBe(true);
        expect(result.blockedFields).toHaveLength(0);
    });
    test('validatePayload rejects in private mode', () => {
        const result = pm.validatePayload({
            language: 'typescript',
            outcome: 'success',
        });
        expect(result.valid).toBe(false);
        expect(result.reason).toContain('private');
    });
    test('validatePayload rejects oversized payloads', () => {
        pm.setMode('community');
        const largePayload = {};
        for (let i = 0; i < 100; i++) {
            largePayload[`field_${i}`] = 'x'.repeat(50);
        }
        const result = pm.validatePayload(largePayload);
        expect(result.valid).toBe(false);
        expect(result.reason).toContain('too large');
    });
    test('case insensitive block detection', () => {
        expect(pm.isBlocked('SOURCE_CODE')).toBe(true);
        expect(pm.isBlocked('File_Path')).toBe(true);
        expect(pm.isBlocked('API_KEY')).toBe(true);
    });
    test('getForbiddenFields returns sorted list', () => {
        const fields = pm.getForbiddenFields();
        expect(fields.length).toBeGreaterThan(10);
        expect(fields).toContain('source_code');
        expect(fields).toContain('file_path');
        expect(fields[0] <= fields[1]).toBe(true);
    });
    test('getMaxPayloadBytes returns 300', () => {
        expect(pm.getMaxPayloadBytes()).toBe(300);
    });
});
//# sourceMappingURL=privacy-manager.test.js.map