Files
bilin/tests/main/interactive-gate.test.ts
T
2026-07-06 17:46:16 +08:00

35 lines
1.2 KiB
TypeScript

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, '<p>有正文</p>')
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)
})
})