feedbackLocalTicketStore.test.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
  2. import { tmpdir } from "node:os";
  3. import { join } from "node:path";
  4. import { afterEach, describe, expect, it } from "vitest";
  5. import { FeedbackLocalTicketStore } from "#src/feedback/feedbackLocalTicketStore.js";
  6. const tempDirs: string[] = [];
  7. afterEach(() => {
  8. for (const dir of tempDirs.splice(0)) {
  9. rmSync(dir, { recursive: true, force: true });
  10. }
  11. });
  12. describe("FeedbackLocalTicketStore", () => {
  13. it("读取旧版匿名反馈时将待评估状态迁移为已提交", async () => {
  14. const rootDir = mkdtempSync(join(tmpdir(), "zcode-feedback-ticket-store-"));
  15. tempDirs.push(rootDir);
  16. writeFileSync(
  17. join(rootDir, "tickets.json"),
  18. JSON.stringify({
  19. tickets: [
  20. {
  21. deviceMid: "device-1",
  22. id: "legacy-ticket",
  23. title: "旧版匿名反馈",
  24. type: "bug",
  25. status: "待评估",
  26. created_at: "2026-07-01T00:00:00.000Z",
  27. updated_at: "2026-07-01T00:00:00.000Z",
  28. },
  29. ],
  30. }),
  31. );
  32. const store = new FeedbackLocalTicketStore(rootDir);
  33. await expect(store.list("device-1")).resolves.toEqual([
  34. {
  35. id: "legacy-ticket",
  36. title: "旧版匿名反馈",
  37. type: "bug",
  38. status: "已提交",
  39. created_at: "2026-07-01T00:00:00.000Z",
  40. updated_at: "2026-07-01T00:00:00.000Z",
  41. },
  42. ]);
  43. });
  44. it("读取未知缓存状态时按接口契约归一为已提交", async () => {
  45. const rootDir = mkdtempSync(join(tmpdir(), "zcode-feedback-ticket-store-"));
  46. tempDirs.push(rootDir);
  47. writeFileSync(
  48. join(rootDir, "tickets.json"),
  49. JSON.stringify({
  50. tickets: [
  51. {
  52. deviceMid: "device-1",
  53. id: "unknown-status-ticket",
  54. title: "未知状态反馈",
  55. type: "bug",
  56. status: "future_status",
  57. created_at: "2026-07-02T00:00:00.000Z",
  58. updated_at: "2026-07-02T00:00:00.000Z",
  59. },
  60. ],
  61. }),
  62. );
  63. const store = new FeedbackLocalTicketStore(rootDir);
  64. await expect(store.list("device-1")).resolves.toEqual([
  65. {
  66. id: "unknown-status-ticket",
  67. title: "未知状态反馈",
  68. type: "bug",
  69. status: "已提交",
  70. created_at: "2026-07-02T00:00:00.000Z",
  71. updated_at: "2026-07-02T00:00:00.000Z",
  72. },
  73. ]);
  74. });
  75. });