list-chapters.test.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import { test, before, after } from 'node:test'
  2. import assert from 'node:assert/strict'
  3. import { run } from '../../src/commands/list-chapters.js'
  4. import { fixtureCtx } from './_helper.js'
  5. let ctx, cleanup
  6. before(async () => {
  7. ;({ ctx, cleanup } = await fixtureCtx())
  8. })
  9. after(async () => {
  10. await cleanup()
  11. })
  12. test('list-chapters --章定位=推进 返回该定位的章节', async () => {
  13. const r = await run([], { 章定位: '推进' }, ctx)
  14. assert.equal(r.ok, true)
  15. const rows = JSON.parse(r.output)
  16. const nums = rows.map((c) => c.chapter_num).sort()
  17. assert.deepEqual(nums, [1, 2])
  18. })
  19. test('list-chapters --章定位=推进 --卷=1 受卷过滤', async () => {
  20. const r = await run([], { 章定位: '推进', 卷: '1' }, ctx)
  21. assert.equal(r.ok, true)
  22. assert.equal(JSON.parse(r.output).length, 2)
  23. })
  24. test('list-chapters 空结果(无日常章)→ ok 且空数组', async () => {
  25. const r = await run([], { 章定位: '日常' }, ctx)
  26. assert.equal(r.ok, true)
  27. assert.deepEqual(JSON.parse(r.output), [])
  28. })
  29. test('list-chapters 缺 --章定位 → ok=false', async () => {
  30. const r = await run([], {}, ctx)
  31. assert.equal(r.ok, false)
  32. })