import { describe, it, expect } from 'vitest'; import { sanitizeFtsQuery, computeCutoff } from '../../src/main/repository/ftsHelpers.js'; describe('sanitizeFtsQuery', () => { it('strips FTS5 special chars', () => { expect(sanitizeFtsQuery('"기획" *회의*')).toBe('기획 회의'); expect(sanitizeFtsQuery('foo: (bar)')).toBe('foo bar'); }); it('keeps Korean + alphanumeric tokens', () => { expect(sanitizeFtsQuery('회의 결재 v2')).toBe('회의 결재 v2'); }); it('collapses whitespace', () => { expect(sanitizeFtsQuery(' 회의 ')).toBe('회의'); }); it('returns empty string for whitespace-only', () => { expect(sanitizeFtsQuery(' ')).toBe(''); }); it('v0.3.9 — dash/caret/backtick 추가 sanitize', () => { expect(sanitizeFtsQuery('key-value')).toBe('key value'); expect(sanitizeFtsQuery('^prefix')).toBe('prefix'); expect(sanitizeFtsQuery('back`tick')).toBe('back tick'); expect(sanitizeFtsQuery('-NOT')).toBe('NOT'); }); }); describe('computeCutoff', () => { // KST = UTC+9. KST 자정 = UTC 전날 15:00. it('daily — KST 오늘 자정 ISO', () => { const now = new Date('2026-05-10T05:30:00Z'); // KST 14:30 expect(computeCutoff('daily', now)).toBe('2026-05-09T15:00:00.000Z'); }); it('weekly — 7일 전 KST 자정', () => { const now = new Date('2026-05-10T05:30:00Z'); expect(computeCutoff('weekly', now)).toBe('2026-05-02T15:00:00.000Z'); }); it('monthly — 30일 전 KST 자정', () => { const now = new Date('2026-05-10T05:30:00Z'); expect(computeCutoff('monthly', now)).toBe('2026-04-09T15:00:00.000Z'); }); });