"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const database_1 = require("../walls/06-memory/database/database");
const memory_event_store_1 = require("../walls/06-memory/stores/memory-event-store");
const memory_search_1 = require("../walls/06-memory/stores/memory-search");
describe('Memory Search', () => {
    beforeAll(() => { (0, database_1.getDb)(); });
    afterEach(() => {
        const db = (0, database_1.getDb)();
        db.prepare('DELETE FROM memory_events WHERE project = ?').run('search-test');
    });
    it('fuzzySearchMemory returns results', () => {
        (0, memory_event_store_1.recordMemoryEvent)({ project: 'search-test', type: 'edit', summary: 'Fixed TypeScript compilation', importance: 5, topic: 'typescript' });
        (0, memory_event_store_1.recordMemoryEvent)({ project: 'search-test', type: 'decision', summary: 'Use React for frontend', importance: 8, topic: 'react' });
        const results = (0, memory_search_1.fuzzySearchMemory)({ query: 'typescript', project: 'search-test' });
        expect(results.length).toBeGreaterThanOrEqual(1);
        expect(results[0].summary).toContain('TypeScript');
    });
    it('fuzzySearchMemory filters by type', () => {
        (0, memory_event_store_1.recordMemoryEvent)({ project: 'search-test', type: 'edit', summary: 'Edit something', importance: 3 });
        (0, memory_event_store_1.recordMemoryEvent)({ project: 'search-test', type: 'decision', summary: 'Decision made', importance: 8 });
        const results = (0, memory_search_1.fuzzySearchMemory)({ query: 'edit', project: 'search-test', type: 'edit' });
        expect(results.every(r => r.type === 'edit')).toBe(true);
    });
    it('fuzzySearchMemory filters by importance', () => {
        (0, memory_event_store_1.recordMemoryEvent)({ project: 'search-test', type: 'edit', summary: 'Low importance', importance: 2 });
        (0, memory_event_store_1.recordMemoryEvent)({ project: 'search-test', type: 'decision', summary: 'High importance', importance: 9 });
        const results = (0, memory_search_1.fuzzySearchMemory)({ query: 'importance', project: 'search-test', minImportance: 5 });
        expect(results.every(r => r.importance >= 5)).toBe(true);
    });
    it('fuzzySearchMemory sortBy importance', () => {
        (0, memory_event_store_1.recordMemoryEvent)({ project: 'search-test', type: 'edit', summary: 'Test sort', importance: 2 });
        (0, memory_event_store_1.recordMemoryEvent)({ project: 'search-test', type: 'decision', summary: 'Test sort high', importance: 9 });
        const results = (0, memory_search_1.fuzzySearchMemory)({ query: 'test sort', project: 'search-test', sortBy: 'importance' });
        expect(results.length).toBeGreaterThanOrEqual(2);
        expect(results[0].importance).toBeGreaterThanOrEqual(results[1].importance);
    });
    it('getSearchSuggestions returns topics', () => {
        (0, memory_event_store_1.recordMemoryEvent)({ project: 'search-test', type: 'edit', summary: 'Edit', importance: 3, topic: 'testing' });
        const suggestions = (0, memory_search_1.getSearchSuggestions)('search-test', 'test');
        expect(suggestions.length).toBeGreaterThanOrEqual(1);
    });
    it('fuzzySearchMemory with no results', () => {
        const results = (0, memory_search_1.fuzzySearchMemory)({ query: 'zzzznonexistent', project: 'search-test' });
        expect(results.length).toBe(0);
    });
});
//# sourceMappingURL=memory-search.test.js.map