
























@@ -70,6 +70,19 @@ function requireZalouserMediaSender(
7070return media;
7171}
727273+function requireRecord(value: unknown, label: string): Record<string, unknown> {
74+if (value === null || typeof value !== "object" || Array.isArray(value)) {
75+throw new Error(`expected ${label} to be a record`);
76+}
77+return value as Record<string, unknown>;
78+}
79+80+function requireSendOptions(
81+mockedSend: ReturnType<typeof vi.mocked<(typeof import("./send.js"))["sendMessageZalouser"]>>,
82+): Record<string, unknown> {
83+return requireRecord(mockedSend.mock.calls[0]?.[2], "Zalouser send options");
84+}
85+7386describe("zalouserPlugin outbound sendPayload", () => {
7487let mockedSend: ReturnType<typeof vi.mocked<(typeof import("./send.js"))["sendMessageZalouser"]>>;
7588@@ -95,12 +108,14 @@ describe("zalouserPlugin outbound sendPayload", () => {
95108to: "group:1471383327500481391",
96109});
9711098-expect(mockedSend).toHaveBeenCalledWith(
99-"1471383327500481391",
100-"hello group",
101-expect.objectContaining({ isGroup: true, textMode: "markdown" }),
102-);
103-expect(result).toMatchObject({ channel: "zalouser", messageId: "zlu-g1" });
111+expect(mockedSend).toHaveBeenCalledOnce();
112+expect(mockedSend.mock.calls[0]?.[0]).toBe("1471383327500481391");
113+expect(mockedSend.mock.calls[0]?.[1]).toBe("hello group");
114+const options = requireSendOptions(mockedSend);
115+expect(options.isGroup).toBe(true);
116+expect(options.textMode).toBe("markdown");
117+expect(result.channel).toBe("zalouser");
118+expect(result.messageId).toBe("zlu-g1");
104119});
105120106121it("treats bare numeric targets as direct chats for backward compatibility", async () => {
@@ -112,12 +127,14 @@ describe("zalouserPlugin outbound sendPayload", () => {
112127to: "987654321",
113128});
114129115-expect(mockedSend).toHaveBeenCalledWith(
116-"987654321",
117-"hello",
118-expect.objectContaining({ isGroup: false, textMode: "markdown" }),
119-);
120-expect(result).toMatchObject({ channel: "zalouser", messageId: "zlu-d1" });
130+expect(mockedSend).toHaveBeenCalledOnce();
131+expect(mockedSend.mock.calls[0]?.[0]).toBe("987654321");
132+expect(mockedSend.mock.calls[0]?.[1]).toBe("hello");
133+const options = requireSendOptions(mockedSend);
134+expect(options.isGroup).toBe(false);
135+expect(options.textMode).toBe("markdown");
136+expect(result.channel).toBe("zalouser");
137+expect(result.messageId).toBe("zlu-d1");
121138});
122139123140it("preserves provider-native group ids when sending to raw g- targets", async () => {
@@ -129,12 +146,14 @@ describe("zalouserPlugin outbound sendPayload", () => {
129146to: "g-1471383327500481391",
130147});
131148132-expect(mockedSend).toHaveBeenCalledWith(
133-"g-1471383327500481391",
134-"hello native group",
135-expect.objectContaining({ isGroup: true, textMode: "markdown" }),
136-);
137-expect(result).toMatchObject({ channel: "zalouser", messageId: "zlu-g-native" });
149+expect(mockedSend).toHaveBeenCalledOnce();
150+expect(mockedSend.mock.calls[0]?.[0]).toBe("g-1471383327500481391");
151+expect(mockedSend.mock.calls[0]?.[1]).toBe("hello native group");
152+const options = requireSendOptions(mockedSend);
153+expect(options.isGroup).toBe(true);
154+expect(options.textMode).toBe("markdown");
155+expect(result.channel).toBe("zalouser");
156+expect(result.messageId).toBe("zlu-g-native");
138157});
139158140159it("passes long markdown through once so formatting happens before chunking", async () => {
@@ -148,17 +167,15 @@ describe("zalouserPlugin outbound sendPayload", () => {
148167});
149168150169expect(mockedSend).toHaveBeenCalledTimes(1);
151-expect(mockedSend).toHaveBeenCalledWith(
152-"987654321",
153-text,
154-expect.objectContaining({
155-isGroup: false,
156-textMode: "markdown",
157-textChunkMode: "length",
158-textChunkLimit: 1200,
159-}),
160-);
161-expect(result).toMatchObject({ channel: "zalouser", messageId: "zlu-code" });
170+expect(mockedSend.mock.calls[0]?.[0]).toBe("987654321");
171+expect(mockedSend.mock.calls[0]?.[1]).toBe(text);
172+const options = requireSendOptions(mockedSend);
173+expect(options.isGroup).toBe(false);
174+expect(options.textMode).toBe("markdown");
175+expect(options.textChunkMode).toBe("length");
176+expect(options.textChunkLimit).toBe(1200);
177+expect(result.channel).toBe("zalouser");
178+expect(result.messageId).toBe("zlu-code");
162179});
163180164181it("declares message adapter durable text and media with receipt proofs", async () => {
@@ -185,40 +202,38 @@ describe("zalouserPlugin outbound sendPayload", () => {
185202const sendText = requireZalouserTextSender(adapter);
186203const sendMedia = requireZalouserMediaSender(adapter);
187204188-await expect(
189-verifyChannelMessageAdapterCapabilityProofs({
190-adapterName: "zalouser",
191- adapter,
192-proofs: {
193-text: async () => {
194-const result = await sendText({
195-cfg: {},
196-to: "user:987654321",
197-text: "hello",
198-});
199-expect(result.receipt.platformMessageIds).toEqual(["zlu-text-1"]);
200-},
201-media: async () => {
202-const result = await sendMedia({
203-cfg: {},
204-to: "user:987654321",
205-text: "image",
206-mediaUrl: "https://example.com/image.png",
207-});
208-expect(result.receipt.platformMessageIds).toEqual(["zlu-media-1"]);
209-},
210-messageSendingHooks: () => {
211-expect(adapter.durableFinal?.capabilities?.messageSendingHooks).toBe(true);
212-},
205+const proofs = await verifyChannelMessageAdapterCapabilityProofs({
206+adapterName: "zalouser",
207+ adapter,
208+proofs: {
209+text: async () => {
210+const result = await sendText({
211+cfg: {},
212+to: "user:987654321",
213+text: "hello",
214+});
215+expect(result.receipt.platformMessageIds).toEqual(["zlu-text-1"]);
213216},
214-}),
215-).resolves.toEqual(
216-expect.arrayContaining([
217-{ capability: "text", status: "verified" },
218-{ capability: "media", status: "verified" },
219-{ capability: "messageSendingHooks", status: "verified" },
220-]),
217+media: async () => {
218+const result = await sendMedia({
219+cfg: {},
220+to: "user:987654321",
221+text: "image",
222+mediaUrl: "https://example.com/image.png",
223+});
224+expect(result.receipt.platformMessageIds).toEqual(["zlu-media-1"]);
225+},
226+messageSendingHooks: () => {
227+expect(adapter.durableFinal?.capabilities?.messageSendingHooks).toBe(true);
228+},
229+},
230+});
231+const proofStatusByCapability = new Map(
232+proofs.map((proof) => [proof.capability, proof.status] as const),
221233);
234+expect(proofStatusByCapability.get("text")).toBe("verified");
235+expect(proofStatusByCapability.get("media")).toBe("verified");
236+expect(proofStatusByCapability.get("messageSendingHooks")).toBe("verified");
222237});
223238});
224239此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。