"use strict";
/**
 * Tests for the useNativeAI hook
 */
Object.defineProperty(exports, "__esModule", { value: true });
const react_hooks_1 = require("@testing-library/react-hooks");
const useNativeAI_1 = require("../useNativeAI");
const native_ai_service_1 = require("../../services/native-ai-service");
// Mock nativeAiService
jest.mock('../../services/native-ai-service', () => {
    return {
        nativeAiService: {
            initialize: jest.fn().mockResolvedValue(undefined),
            shutdown: jest.fn().mockResolvedValue(undefined),
            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
                    }
                };
            }),
            embeddings: jest.fn().mockImplementation(async (texts) => {
                return texts.map(() => Array(1536).fill(0).map(() => Math.random() - 0.5));
            }),
            analyzeDocument: jest.fn().mockImplementation(async () => {
                return {
                    summary: 'Test summary',
                    keyPoints: ['Point 1', 'Point 2'],
                    sentiment: 'positive'
                };
            }),
            generateRFPContent: jest.fn().mockImplementation(async () => {
                return 'Test RFP content';
            }),
            generateComplianceReport: jest.fn().mockImplementation(async () => {
                return {
                    status: 'compliant',
                    analysis: 'Test analysis',
                    recommendations: ['Rec 1', 'Rec 2'],
                    riskLevel: 'low'
                };
            }),
            getPlugins: jest.fn().mockReturnValue([]),
            registerPlugin: jest.fn().mockResolvedValue(undefined)
        }
    };
});
// Mock pluginManager
jest.mock('../../services/native-ai/plugin-system', () => {
    return {
        pluginManager: {
            isInitialized: jest.fn().mockReturnValue(false)
        }
    };
});
describe('useNativeAI', () => {
    afterEach(() => {
        jest.clearAllMocks();
    });
    test('initializes the plugin system on mount', async () => {
        const { result, waitForNextUpdate } = (0, react_hooks_1.renderHook)(() => (0, useNativeAI_1.useNativeAI)());
        // Initial state
        expect(result.current.initialized).toBe(false);
        expect(result.current.loading).toBe(true);
        // Wait for initialization
        await waitForNextUpdate();
        // After initialization
        expect(result.current.initialized).toBe(true);
        expect(result.current.loading).toBe(false);
        expect(native_ai_service_1.nativeAiService.initialize).toHaveBeenCalled();
    });
    test('chat function calls nativeAiService.chat', async () => {
        const { result, waitForNextUpdate } = (0, react_hooks_1.renderHook)(() => (0, useNativeAI_1.useNativeAI)('test-provider'));
        // Wait for initialization
        await waitForNextUpdate();
        // Create request
        const request = {
            model: 'claude-3-sonnet',
            messages: [
                {
                    role: 'user',
                    content: 'Hello, Claude!'
                }
            ]
        };
        // Call chat function
        const response = await result.current.chat(request);
        // Verify chat was called with correct parameters
        expect(native_ai_service_1.nativeAiService.chat).toHaveBeenCalledWith({
            ...request,
            provider: 'test-provider'
        }, undefined);
        // Verify response
        expect(response).toBeDefined();
        expect(response.choices[0].message.content).toBe('Mock response for testing');
    });
    test('embeddings function calls nativeAiService.embeddings', async () => {
        const { result, waitForNextUpdate } = (0, react_hooks_1.renderHook)(() => (0, useNativeAI_1.useNativeAI)('test-provider'));
        // Wait for initialization
        await waitForNextUpdate();
        // Call embeddings function
        const texts = ['Test text 1', 'Test text 2'];
        const embeddings = await result.current.embeddings(texts);
        // Verify embeddings was called with correct parameters
        expect(native_ai_service_1.nativeAiService.embeddings).toHaveBeenCalledWith(texts, undefined, 'test-provider');
        // Verify response
        expect(embeddings).toBeDefined();
        expect(embeddings.length).toBe(2);
        expect(embeddings[0].length).toBe(1536);
    });
    test('analyzeDocument function calls nativeAiService.analyzeDocument', async () => {
        const { result, waitForNextUpdate } = (0, react_hooks_1.renderHook)(() => (0, useNativeAI_1.useNativeAI)('test-provider'));
        // Wait for initialization
        await waitForNextUpdate();
        // Call analyzeDocument function
        const document = 'Test document';
        const options = {
            detailed: true,
            categories: ['technical', 'legal']
        };
        const analysis = await result.current.analyzeDocument(document, options);
        // Verify analyzeDocument was called with correct parameters
        expect(native_ai_service_1.nativeAiService.analyzeDocument).toHaveBeenCalledWith(document, {
            ...options,
            providerId: 'test-provider'
        });
        // Verify response
        expect(analysis).toBeDefined();
        expect(analysis.summary).toBe('Test summary');
        expect(analysis.keyPoints).toContain('Point 1');
        expect(analysis.sentiment).toBe('positive');
    });
    test('generateRFPContent function calls nativeAiService.generateRFPContent', async () => {
        const { result, waitForNextUpdate } = (0, react_hooks_1.renderHook)(() => (0, useNativeAI_1.useNativeAI)('test-provider'));
        // Wait for initialization
        await waitForNextUpdate();
        // Call generateRFPContent function
        const rfpDocument = 'Test RFP document';
        const requirements = ['Requirement 1', 'Requirement 2'];
        const content = await result.current.generateRFPContent(rfpDocument, requirements);
        // Verify generateRFPContent was called with correct parameters
        expect(native_ai_service_1.nativeAiService.generateRFPContent).toHaveBeenCalledWith(rfpDocument, requirements, 'test-provider');
        // Verify response
        expect(content).toBe('Test RFP content');
    });
    test('generateComplianceReport function calls nativeAiService.generateComplianceReport', async () => {
        const { result, waitForNextUpdate } = (0, react_hooks_1.renderHook)(() => (0, useNativeAI_1.useNativeAI)('test-provider'));
        // Wait for initialization
        await waitForNextUpdate();
        // Call generateComplianceReport function
        const requirements = ['Requirement 1', 'Requirement 2'];
        const implementationDetails = 'Implementation details';
        const report = await result.current.generateComplianceReport(requirements, implementationDetails);
        // Verify generateComplianceReport was called with correct parameters
        expect(native_ai_service_1.nativeAiService.generateComplianceReport).toHaveBeenCalledWith(requirements, implementationDetails, 'test-provider');
        // Verify response
        expect(report).toBeDefined();
        expect(report.status).toBe('compliant');
        expect(report.analysis).toBe('Test analysis');
        expect(report.recommendations).toContain('Rec 1');
        expect(report.riskLevel).toBe('low');
    });
    test('getPlugins function calls nativeAiService.getPlugins', async () => {
        const { result, waitForNextUpdate } = (0, react_hooks_1.renderHook)(() => (0, useNativeAI_1.useNativeAI)());
        // Wait for initialization
        await waitForNextUpdate();
        // Call getPlugins function
        const plugins = result.current.getPlugins();
        // Verify getPlugins was called
        expect(native_ai_service_1.nativeAiService.getPlugins).toHaveBeenCalled();
        // Verify response
        expect(plugins).toEqual([]);
    });
    test('registerPlugin function calls nativeAiService.registerPlugin', async () => {
        const { result, waitForNextUpdate } = (0, react_hooks_1.renderHook)(() => (0, useNativeAI_1.useNativeAI)());
        // Wait for initialization
        await waitForNextUpdate();
        // Create mock plugin
        const mockPlugin = {
            id: 'test-plugin',
            name: 'Test Plugin',
            version: '1.0.0',
            type: 'provider',
            capabilities: ['test'],
            metadata: {},
            initialize: jest.fn(),
            isInitialized: jest.fn().mockReturnValue(true),
            shutdown: jest.fn()
        };
        // Call registerPlugin function
        await result.current.registerPlugin(mockPlugin);
        // Verify registerPlugin was called with correct parameters
        expect(native_ai_service_1.nativeAiService.registerPlugin).toHaveBeenCalledWith(mockPlugin);
    });
    test('throws error when calling methods before initialization', async () => {
        // Mock isInitialized to return false for this test
        native_ai_service_1.nativeAiService.initialize.mockRejectedValueOnce(new Error('Initialization failed'));
        const { result, waitForNextUpdate } = (0, react_hooks_1.renderHook)(() => (0, useNativeAI_1.useNativeAI)());
        // Wait for initialization to fail
        await waitForNextUpdate();
        // Verify error state
        expect(result.current.initialized).toBe(false);
        expect(result.current.error).toBeDefined();
        // Verify methods throw errors
        await expect(result.current.chat({ messages: [] })).rejects.toThrow('Native AI not initialized');
        await expect(result.current.embeddings(['test'])).rejects.toThrow('Native AI not initialized');
        await expect(result.current.analyzeDocument('test')).rejects.toThrow('Native AI not initialized');
    });
});
//# sourceMappingURL=useNativeAI.test.js.map