




























@@ -29,6 +29,47 @@ function baseCtx(payload: ReplyPayload) {
2929};
3030}
313132+type ZalouserOutbound = NonNullable<typeof zalouserPlugin.outbound>;
33+type ZalouserSendPayload = NonNullable<ZalouserOutbound["sendPayload"]>;
34+type ZalouserMessageAdapter = NonNullable<typeof zalouserPlugin.message>;
35+type ZalouserMessageSender = NonNullable<ZalouserMessageAdapter["send"]>;
36+37+function requireZalouserSendPayload(): ZalouserSendPayload {
38+const sendPayload = zalouserPlugin.outbound?.sendPayload;
39+if (!sendPayload) {
40+throw new Error("Expected Zalouser outbound sendPayload");
41+}
42+return sendPayload;
43+}
44+45+function requireZalouserMessageAdapter(): ZalouserMessageAdapter {
46+const adapter = zalouserPlugin.message;
47+if (!adapter) {
48+throw new Error("Expected Zalouser message adapter");
49+}
50+return adapter;
51+}
52+53+function requireZalouserTextSender(
54+adapter: ZalouserMessageAdapter,
55+): NonNullable<ZalouserMessageSender["text"]> {
56+const text = adapter.send?.text;
57+if (!text) {
58+throw new Error("Expected Zalouser message adapter text sender");
59+}
60+return text;
61+}
62+63+function requireZalouserMediaSender(
64+adapter: ZalouserMessageAdapter,
65+): NonNullable<ZalouserMessageSender["media"]> {
66+const media = adapter.send?.media;
67+if (!media) {
68+throw new Error("Expected Zalouser message adapter media sender");
69+}
70+return media;
71+}
72+3273describe("zalouserPlugin outbound sendPayload", () => {
3374let mockedSend: ReturnType<typeof vi.mocked<(typeof import("./send.js"))["sendMessageZalouser"]>>;
3475@@ -47,8 +88,9 @@ describe("zalouserPlugin outbound sendPayload", () => {
47884889it("group target delegates with isGroup=true and stripped threadId", async () => {
4990mockedSend.mockResolvedValue({ ok: true, messageId: "zlu-g1" } as never);
91+const sendPayload = requireZalouserSendPayload();
509251-const result = await zalouserPlugin.outbound!.sendPayload!({
93+const result = await sendPayload({
5294 ...baseCtx({ text: "hello group" }),
5395to: "group:1471383327500481391",
5496});
@@ -63,8 +105,9 @@ describe("zalouserPlugin outbound sendPayload", () => {
6310564106it("treats bare numeric targets as direct chats for backward compatibility", async () => {
65107mockedSend.mockResolvedValue({ ok: true, messageId: "zlu-d1" } as never);
108+const sendPayload = requireZalouserSendPayload();
6610967-const result = await zalouserPlugin.outbound!.sendPayload!({
110+const result = await sendPayload({
68111 ...baseCtx({ text: "hello" }),
69112to: "987654321",
70113});
@@ -79,8 +122,9 @@ describe("zalouserPlugin outbound sendPayload", () => {
7912280123it("preserves provider-native group ids when sending to raw g- targets", async () => {
81124mockedSend.mockResolvedValue({ ok: true, messageId: "zlu-g-native" } as never);
125+const sendPayload = requireZalouserSendPayload();
8212683-const result = await zalouserPlugin.outbound!.sendPayload!({
127+const result = await sendPayload({
84128 ...baseCtx({ text: "hello native group" }),
85129to: "g-1471383327500481391",
86130});
@@ -96,8 +140,9 @@ describe("zalouserPlugin outbound sendPayload", () => {
96140it("passes long markdown through once so formatting happens before chunking", async () => {
97141const text = `**${"a".repeat(2501)}**`;
98142mockedSend.mockResolvedValue({ ok: true, messageId: "zlu-code" } as never);
143+const sendPayload = requireZalouserSendPayload();
99144100-const result = await zalouserPlugin.outbound!.sendPayload!({
145+const result = await sendPayload({
101146 ...baseCtx({ text }),
102147to: "987654321",
103148});
@@ -136,33 +181,34 @@ describe("zalouserPlugin outbound sendPayload", () => {
136181}),
137182},
138183);
184+const adapter = requireZalouserMessageAdapter();
185+const sendText = requireZalouserTextSender(adapter);
186+const sendMedia = requireZalouserMediaSender(adapter);
139187140188await expect(
141189verifyChannelMessageAdapterCapabilityProofs({
142190adapterName: "zalouser",
143-adapter: zalouserPlugin.message!,
191+ adapter,
144192proofs: {
145193text: async () => {
146-const result = await zalouserPlugin.message?.send?.text?.({
194+const result = await sendText({
147195cfg: {},
148196to: "user:987654321",
149197text: "hello",
150198});
151-expect(result?.receipt.platformMessageIds).toEqual(["zlu-text-1"]);
199+expect(result.receipt.platformMessageIds).toEqual(["zlu-text-1"]);
152200},
153201media: async () => {
154-const result = await zalouserPlugin.message?.send?.media?.({
202+const result = await sendMedia({
155203cfg: {},
156204to: "user:987654321",
157205text: "image",
158206mediaUrl: "https://example.com/image.png",
159207});
160-expect(result?.receipt.platformMessageIds).toEqual(["zlu-media-1"]);
208+expect(result.receipt.platformMessageIds).toEqual(["zlu-media-1"]);
161209},
162210messageSendingHooks: () => {
163-expect(zalouserPlugin.message?.durableFinal?.capabilities?.messageSendingHooks).toBe(
164-true,
165-);
211+expect(adapter.durableFinal?.capabilities?.messageSendingHooks).toBe(true);
166212},
167213},
168214}),
@@ -194,8 +240,9 @@ describe("zalouserPlugin outbound payload contract", () => {
194240text: "",
195241payload: params.payload,
196242};
243+const sendPayload = requireZalouserSendPayload();
197244return {
198-run: async () => await zalouserPlugin.outbound!.sendPayload!(ctx),
245+run: async () => await sendPayload(ctx),
199246sendMock: mockedSend,
200247to: "987654321",
201248};
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。