| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- import { describe, expect, it, vi } from "vitest";
- import type { IFeedbackService } from "@zcode/services";
- import {
- submitSupplementFeedback,
- type SupplementAttachmentDraft,
- } from "@/feedback/FeedbackSupplementComposer.js";
- describe("FeedbackSupplementComposer", () => {
- it("creates the supplemental message before uploading attachments to that message", async () => {
- const calls: string[] = [];
- const attachment: SupplementAttachmentDraft = {
- id: "att-local",
- filename: "detail.log",
- contentType: "text/plain",
- dataBase64: "ZGV0YWls",
- size: 6,
- kind: "other",
- };
- const feedbackService = {
- comment: vi.fn(async () => {
- calls.push("comment");
- return {
- id: 1,
- message_id: "msg_123",
- body: "补充说明",
- is_staff: false,
- created_at: "2026-06-25T00:00:00.000Z",
- };
- }),
- uploadAttachmentData: vi.fn(async (_ticketId, _kind, file) => {
- calls.push("upload");
- expect(file.messageId).toBe("msg_123");
- return {
- id: 2,
- kind: "other",
- filename: file.filename,
- size: 6,
- redacted: false,
- created_at: "2026-06-25T00:00:00.000Z",
- };
- }),
- } as unknown as IFeedbackService;
- await submitSupplementFeedback({
- ticketId: "tkt_1",
- feedbackService,
- comment: "补充说明",
- attachments: [attachment],
- formatUploadedAttachments: (names) => `附件:${names.join("、")}`,
- });
- expect(calls).toEqual(["comment", "upload"]);
- expect(feedbackService.comment).toHaveBeenCalledWith("tkt_1", "补充说明\n\n附件:detail.log");
- expect(feedbackService.uploadAttachmentData).toHaveBeenCalledWith("tkt_1", "other", {
- dataBase64: "ZGV0YWls",
- filename: "detail.log",
- contentType: "text/plain",
- messageId: "msg_123",
- });
- });
- });
|