feedbackSupplementComposer.test.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import { describe, expect, it, vi } from "vitest";
  2. import type { IFeedbackService } from "@zcode/services";
  3. import {
  4. submitSupplementFeedback,
  5. type SupplementAttachmentDraft,
  6. } from "@/feedback/FeedbackSupplementComposer.js";
  7. describe("FeedbackSupplementComposer", () => {
  8. it("creates the supplemental message before uploading attachments to that message", async () => {
  9. const calls: string[] = [];
  10. const attachment: SupplementAttachmentDraft = {
  11. id: "att-local",
  12. filename: "detail.log",
  13. contentType: "text/plain",
  14. dataBase64: "ZGV0YWls",
  15. size: 6,
  16. kind: "other",
  17. };
  18. const feedbackService = {
  19. comment: vi.fn(async () => {
  20. calls.push("comment");
  21. return {
  22. id: 1,
  23. message_id: "msg_123",
  24. body: "补充说明",
  25. is_staff: false,
  26. created_at: "2026-06-25T00:00:00.000Z",
  27. };
  28. }),
  29. uploadAttachmentData: vi.fn(async (_ticketId, _kind, file) => {
  30. calls.push("upload");
  31. expect(file.messageId).toBe("msg_123");
  32. return {
  33. id: 2,
  34. kind: "other",
  35. filename: file.filename,
  36. size: 6,
  37. redacted: false,
  38. created_at: "2026-06-25T00:00:00.000Z",
  39. };
  40. }),
  41. } as unknown as IFeedbackService;
  42. await submitSupplementFeedback({
  43. ticketId: "tkt_1",
  44. feedbackService,
  45. comment: "补充说明",
  46. attachments: [attachment],
  47. formatUploadedAttachments: (names) => `附件:${names.join("、")}`,
  48. });
  49. expect(calls).toEqual(["comment", "upload"]);
  50. expect(feedbackService.comment).toHaveBeenCalledWith("tkt_1", "补充说明\n\n附件:detail.log");
  51. expect(feedbackService.uploadAttachmentData).toHaveBeenCalledWith("tkt_1", "other", {
  52. dataBase64: "ZGV0YWls",
  53. filename: "detail.log",
  54. contentType: "text/plain",
  55. messageId: "msg_123",
  56. });
  57. });
  58. });