read-timeline.test.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { test, before, after } from 'node:test'
  2. import assert from 'node:assert/strict'
  3. import { run } from '../../src/commands/read-timeline.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('read-timeline --current-and-prev 返回时间线数组', async () => {
  13. const r = await run([], { 'current-and-prev': true }, ctx)
  14. assert.equal(r.ok, true)
  15. const timeline = JSON.parse(r.output)
  16. assert.ok(Array.isArray(timeline))
  17. assert.ok(timeline.length >= 1)
  18. })
  19. test('read-timeline --current-volume 返回当前卷时间线', async () => {
  20. const r = await run([], { 'current-volume': true }, ctx)
  21. assert.equal(r.ok, true)
  22. assert.ok(Array.isArray(JSON.parse(r.output)))
  23. })
  24. test('read-timeline --卷=1 返回指定卷时间线', async () => {
  25. const r = await run([], { 卷: '1' }, ctx)
  26. assert.equal(r.ok, true)
  27. assert.ok(JSON.parse(r.output).length >= 1)
  28. })
  29. test('read-timeline --在场=林晚 只返回该角色在场的行', async () => {
  30. const r = await run([], { 在场: '林晚' }, ctx)
  31. assert.equal(r.ok, true)
  32. const rows = JSON.parse(r.output)
  33. assert.ok(rows.length >= 1)
  34. assert.ok(rows.every((e) => e.在场.includes('林晚')))
  35. })
  36. test('read-timeline 无任何选项 → ok=false(提示需指定)', async () => {
  37. const r = await run([], {}, ctx)
  38. assert.equal(r.ok, false)
  39. })