diff --git a/src/main/repository/NoteRepository.ts b/src/main/repository/NoteRepository.ts index 679ec69..aa766a6 100644 --- a/src/main/repository/NoteRepository.ts +++ b/src/main/repository/NoteRepository.ts @@ -61,6 +61,10 @@ export class NoteRepository { .prepare(`INSERT INTO notes (id, raw_text, ai_status, created_at, updated_at) VALUES (?, ?, ?, ?, ?)`) .run(id, input.rawText, aiStatus, now, now); + this.db + .prepare(`INSERT INTO note_revisions (note_id, raw_text, edited_at, edited_by) + VALUES (?, ?, ?, 'capture')`) + .run(id, input.rawText, now); // pending_jobs 는 'pending' 일 때만 생성 — 'disabled' 노트는 worker 가 처리 안 함. if (aiStatus === 'pending') { this.db diff --git a/tests/unit/NoteRepository.test.ts b/tests/unit/NoteRepository.test.ts index 171af32..3fe82cd 100644 --- a/tests/unit/NoteRepository.test.ts +++ b/tests/unit/NoteRepository.test.ts @@ -1054,3 +1054,23 @@ describe('NoteRepository.countByAiStatus', () => { expect(repo.countByAiStatus('done')).toBe(0); }); }); + +describe('NoteRepository — note_revisions', () => { + let db: Database.Database; + let repo: NoteRepository; + + beforeEach(() => { + db = new Database(':memory:'); + runMigrations(db); + repo = new NoteRepository(db); + }); + + it('create() 가 첫 revision (edited_by=capture) 을 INSERT 한다', () => { + const { id } = repo.create({ rawText: 'hello' }); + const rows = db + .prepare(`SELECT raw_text, edited_by FROM note_revisions WHERE note_id=?`) + .all(id) as Array<{ raw_text: string; edited_by: string }>; + expect(rows).toHaveLength(1); + expect(rows[0]).toEqual({ raw_text: 'hello', edited_by: 'capture' }); + }); +});