feedbackSupplementComposer.test.ts 2.2 KB

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