Files
inkling/tests/unit/m008.test.ts
2026-05-15 09:47:23 +09:00

36 lines
1.6 KiB
TypeScript

import { describe, it, expect, beforeEach, afterEach } from 'vitest';
import Database from 'better-sqlite3';
import { runMigrations } from '../../src/main/db/migrations/index.js';
describe('m008 notebooks migration', () => {
let db: Database.Database;
beforeEach(() => { db = new Database(':memory:'); db.pragma('foreign_keys = ON'); });
afterEach(() => { db.close(); });
it('fresh DB: notebooks 테이블 + default "기본" notebook 생성', () => {
runMigrations(db);
const row = db.prepare(`SELECT name FROM notebooks`).get() as { name: string };
expect(row.name).toBe('기본');
});
it('기존 notes 가 default notebook 으로 마이그레이션 — fresh insert 는 NULL 유지', () => {
runMigrations(db);
const defaultId = (db.prepare(`SELECT id FROM notebooks`).get() as { id: string }).id;
db.prepare(`INSERT INTO notes(id,raw_text,ai_status,created_at,updated_at,status) VALUES('n1','t','pending','2026-05-14','2026-05-14','active')`).run();
const r = db.prepare(`SELECT notebook_id FROM notes WHERE id='n1'`).get() as { notebook_id: string | null };
expect(r.notebook_id).toBeNull(); // m008 의 UPDATE 는 migration 시점의 NULL 만 채움
});
it('archived 잔류 노트가 있다면 completed 로 통합', () => {
runMigrations(db);
expect(() => db.prepare(`SELECT COUNT(*) FROM notes WHERE status='archived'`).get()).not.toThrow();
});
it('UNIQUE index 가 같은 이름 중복 INSERT 거부', () => {
runMigrations(db);
expect(() =>
db.prepare(`INSERT INTO notebooks(id,name,created_at,updated_at) VALUES('x','기본','t','t')`).run()
).toThrow();
});
});