"use strict";
/**
 * Tests for the BFUI Adapter
 */
Object.defineProperty(exports, "__esModule", { value: true });
const bfui_adapter_1 = require("../bfui-adapter");
const provider_adapter_1 = require("../provider-adapter");
const plugin_system_1 = require("../plugin-system");
// Mock provider adapter
jest.mock('../provider-adapter', () => {
    return {
        ProviderAdapter: jest.fn().mockImplementation(() => {
            return {
                chat: jest.fn().mockImplementation(async (request) => {
                    return {
                        id: 'test-response',
                        model: request.model || 'claude-3-sonnet',
                        choices: [
                            {
                                index: 0,
                                message: {
                                    role: 'assistant',
                                    content: 'Mock response for testing'
                                },
                                finish_reason: 'stop'
                            }
                        ],
                        usage: {
                            prompt_tokens: 10,
                            completion_tokens: 20,
                            total_tokens: 30
                        }
                    };
                })
            };
        }),
        ProviderAdapterError: class ProviderAdapterError extends Error {
            constructor(message, code, details) {
                super(message);
                this.name = 'ProviderAdapterError';
                this.code = code;
                this.details = details;
            }
        }
    };
});
// Mock plugin manager
jest.mock('../plugin-system', () => {
    return {
        pluginManager: {
            getDefaultProvider: jest.fn().mockImplementation(() => {
                return new (jest.requireActual('../../../examples/plugins/anthropic-provider-plugin')).AnthropicProviderPlugin();
            }),
            getProviderPlugin: jest.fn().mockImplementation((id) => {
                if (id === 'anthropic-provider') {
                    return new (jest.requireActual('../../../examples/plugins/anthropic-provider-plugin')).AnthropicProviderPlugin();
                }
                return undefined;
            }),
            isInitialized: jest.fn().mockReturnValue(true)
        }
    };
});
describe('BFUIAdapter', () => {
    let adapter;
    beforeEach(() => {
        adapter = new bfui_adapter_1.BFUIAdapter();
    });
    afterEach(() => {
        jest.clearAllMocks();
    });
    test('constructor creates an adapter with default provider', () => {
        expect(adapter).toBeDefined();
        expect(provider_adapter_1.ProviderAdapter).toHaveBeenCalled();
    });
    test('constructor accepts a provider ID', () => {
        const adapter = new bfui_adapter_1.BFUIAdapter('anthropic-provider');
        expect(adapter).toBeDefined();
        expect(plugin_system_1.pluginManager.getProviderPlugin).toHaveBeenCalledWith('anthropic-provider');
        expect(provider_adapter_1.ProviderAdapter).toHaveBeenCalled();
    });
    test('constructor accepts a provider adapter', () => {
        const providerAdapter = new provider_adapter_1.ProviderAdapter('anthropic-provider');
        const adapter = new bfui_adapter_1.BFUIAdapter(providerAdapter);
        expect(adapter).toBeDefined();
    });
    test('analyzeDocument calls chat with correct parameters', async () => {
        const document = 'This is a test document for analysis.';
        const options = {
            detailed: true,
            categories: ['technical', 'legal']
        };
        const result = await adapter.analyzeDocument(document, options);
        expect(result).toBeDefined();
        expect(result.summary).toBeDefined();
        expect(result.keyPoints).toBeDefined();
        expect(result.sentiment).toBeDefined();
        // Verify that chat was called with correct parameters
        const providerAdapter = new provider_adapter_1.ProviderAdapter('anthropic-provider');
        expect(providerAdapter.chat).toHaveBeenCalled();
    });
    test('generateRFPContent calls chat with correct parameters', async () => {
        const rfpDocument = 'This is a test RFP document.';
        const requirements = ['Requirement 1', 'Requirement 2'];
        const result = await adapter.generateRFPContent(rfpDocument, requirements);
        expect(result).toBeDefined();
        // Verify that chat was called with correct parameters
        const providerAdapter = new provider_adapter_1.ProviderAdapter('anthropic-provider');
        expect(providerAdapter.chat).toHaveBeenCalled();
    });
    test('generateComplianceReport calls chat with correct parameters', async () => {
        const requirements = ['Requirement 1', 'Requirement 2'];
        const implementationDetails = 'Implementation details for testing.';
        const result = await adapter.generateComplianceReport(requirements, implementationDetails);
        expect(result).toBeDefined();
        expect(result.status).toBeDefined();
        expect(result.analysis).toBeDefined();
        expect(result.recommendations).toBeDefined();
        expect(result.riskLevel).toBeDefined();
        // Verify that chat was called with correct parameters
        const providerAdapter = new provider_adapter_1.ProviderAdapter('anthropic-provider');
        expect(providerAdapter.chat).toHaveBeenCalled();
    });
    test('parseDocumentAnalysis correctly extracts information', () => {
        const content = `
# Analysis

## Summary
This is a test summary for document analysis.

## Key Points
- Key point 1
- Key point 2
- Key point 3

## Sentiment
Positive

## Categories
Technical: 85
Legal: 40
`;
        // @ts-ignore - accessing private method for testing
        const result = adapter.parseDocumentAnalysis(content, ['technical', 'legal']);
        expect(result.summary).toBe('This is a test summary for document analysis.');
        expect(result.keyPoints).toContain('Key point 1');
        expect(result.keyPoints).toContain('Key point 2');
        expect(result.keyPoints).toContain('Key point 3');
        expect(result.sentiment).toBe('positive');
        expect(result.categories).toBeDefined();
        expect(result.categories?.['technical']).toBe(85);
        expect(result.categories?.['legal']).toBe(40);
    });
    test('parseComplianceReport correctly extracts information', () => {
        const content = `
# Compliance Report

## Compliance Status
partially_compliant

## Analysis
This is a test analysis for compliance report.

## Recommendations
- Recommendation 1
- Recommendation 2
- Recommendation 3

## Risk Level
medium
`;
        // @ts-ignore - accessing private method for testing
        const result = adapter.parseComplianceReport(content);
        expect(result.status).toBe('partially_compliant');
        expect(result.analysis).toBe('This is a test analysis for compliance report.');
        expect(result.recommendations).toContain('Recommendation 1');
        expect(result.recommendations).toContain('Recommendation 2');
        expect(result.recommendations).toContain('Recommendation 3');
        expect(result.riskLevel).toBe('medium');
    });
});
//# sourceMappingURL=bfui-adapter.test.js.map