import { describe, it, expect, beforeEach, afterEach } from 'vitest' import { DatabaseSync } from 'node:sqlite' import { migrate } from '../../src/main/db/migrate' import { ChapterRepository } from '../../src/main/db/repositories/chapter.repo' import { VolumeRepository } from '../../src/main/db/repositories/volume.repo' import { OutlineRepository } from '../../src/main/db/repositories/outline.repo' import { checkInteractiveGate } from '../../src/main/services/interactive-gate.service' import type { SqliteDb } from '../../src/main/db/types' describe('checkInteractiveGate', () => { let db: SqliteDb beforeEach(() => { db = new DatabaseSync(':memory:') migrate(db) }) afterEach(() => db.close()) it('IT-INT-05: rejects empty book', () => { expect(checkInteractiveGate(db).eligible).toBe(false) }) it('IT-INT-05: accepts book with chapter content', () => { const volId = new VolumeRepository(db).create('卷一', 0).id new ChapterRepository(db).create(volId, '第一章', 0, '

有正文

') expect(checkInteractiveGate(db).eligible).toBe(true) }) it('IT-INT-05: accepts book with outline only', () => { new OutlineRepository(db).create(null, '节点', 0) expect(checkInteractiveGate(db).eligible).toBe(true) }) })