ThreadLedgerReader.test.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { test } from 'node:test'
  2. import assert from 'node:assert/strict'
  3. import path from 'node:path'
  4. import { fileURLToPath } from 'node:url'
  5. import { ThreadLedgerReader } from '../../../src/storage/adapters/ThreadLedgerReader.js'
  6. const __dirname = path.dirname(fileURLToPath(import.meta.url))
  7. const fixtureRoot = path.join(__dirname, '../../fixtures/sample-book')
  8. test('readBasicInfo:读取伏笔基本信息', async () => {
  9. const reader = new ThreadLedgerReader(fixtureRoot)
  10. const result = await reader.readBasicInfo('伏笔-001')
  11. assert.equal(result.ok, true)
  12. assert.equal(result.data.强度, '高')
  13. assert.equal(result.data.状态, '进行')
  14. assert.equal(result.data.开启章, 1)
  15. assert.equal(result.data.预计收尾, '第3卷')
  16. })
  17. test('readBasicInfo:不存在的条目', async () => {
  18. const reader = new ThreadLedgerReader(fixtureRoot)
  19. const result = await reader.readBasicInfo('伏笔-999')
  20. assert.equal(result.ok, false)
  21. assert.ok(result.error.includes('不存在'))
  22. })
  23. test('readHistory:读取履历', async () => {
  24. const reader = new ThreadLedgerReader(fixtureRoot)
  25. const result = await reader.readHistory('伏笔-001')
  26. assert.equal(result.ok, true)
  27. assert.equal(result.history.length, 1)
  28. assert.equal(result.history[0].章号, 1)
  29. assert.ok(result.history[0].原文.includes('埋下'))
  30. })
  31. test('readClosurePlan:读取收尾计划', async () => {
  32. const reader = new ThreadLedgerReader(fixtureRoot)
  33. const result = await reader.readClosurePlan('伏笔-001')
  34. assert.equal(result.ok, true)
  35. assert.ok(result.plan.includes('第三卷揭晓'))
  36. })
  37. test('readDescription:读取描述', async () => {
  38. const reader = new ThreadLedgerReader(fixtureRoot)
  39. const result = await reader.readDescription('伏笔-001')
  40. assert.equal(result.ok, true)
  41. assert.ok(result.description.includes('神秘老者的真实身份'))
  42. })