























@@ -129,6 +129,30 @@ function resolveMatrixSender(deps: DeliverOutboundArgs["deps"]): MatrixSendFn {
129129return sender as MatrixSendFn;
130130}
131131132+function requireMockCallArg(
133+mockFn: { mock: { calls: unknown[][] } },
134+label: string,
135+index = 0,
136+): Record<string, unknown> {
137+const arg = mockFn.mock.calls[index]?.[0] as Record<string, unknown> | undefined;
138+if (!arg) {
139+throw new Error(`expected ${label} call #${index + 1}`);
140+}
141+return arg;
142+}
143+144+function requireMockCall(
145+mockFn: { mock: { calls: unknown[][] } },
146+label: string,
147+index = 0,
148+): unknown[] {
149+const call = mockFn.mock.calls[index];
150+if (!call) {
151+throw new Error(`expected ${label} call #${index + 1}`);
152+}
153+return call;
154+}
155+132156function withMatrixChannel(result: Awaited<ReturnType<MatrixSendFn>>) {
133157return {
134158channel: "matrix" as const,
@@ -727,10 +751,9 @@ describe("deliverOutboundPayloads", () => {
727751expect(failureParams?.kind).toBe("text");
728752expect(failureParams?.attemptToken).toBe("pending-2");
729753expect(failureParams?.error).toBeInstanceOf(Error);
730-expect(queueMocks.failDelivery).toHaveBeenCalledWith(
731-"mock-queue-id",
732-expect.stringContaining("native send failed"),
733-);
754+const failDeliveryCall = requireMockCall(queueMocks.failDelivery, "failDelivery");
755+expect(failDeliveryCall[0]).toBe("mock-queue-id");
756+expect(String(failDeliveryCall[1])).toContain("native send failed");
734757});
735758736759it("preserves native send errors when failure cleanup throws", async () => {
@@ -784,10 +807,9 @@ describe("deliverOutboundPayloads", () => {
784807expect(failureParams?.kind).toBe("text");
785808expect(failureParams?.attemptToken).toBe("pending-2");
786809expect(failureParams?.error).toBeInstanceOf(Error);
787-expect(queueMocks.failDelivery).toHaveBeenCalledWith(
788-"mock-queue-id",
789-expect.stringContaining("native send failed"),
790-);
810+const failDeliveryCall = requireMockCall(queueMocks.failDelivery, "failDelivery");
811+expect(failDeliveryCall[0]).toBe("mock-queue-id");
812+expect(String(failDeliveryCall[1])).toContain("native send failed");
791813});
792814793815it("preserves successful sends when the success hook throws", async () => {
@@ -957,10 +979,9 @@ describe("deliverOutboundPayloads", () => {
957979958980expect(queueMocks.markDeliveryPlatformSendAttemptStarted).toHaveBeenCalledWith("mock-queue-id");
959981expect(sendMatrix).not.toHaveBeenCalled();
960-expect(queueMocks.failDelivery).toHaveBeenCalledWith(
961-"mock-queue-id",
962-expect.stringContaining("marker offline"),
963-);
982+const failDeliveryCall = requireMockCall(queueMocks.failDelivery, "failDelivery");
983+expect(failDeliveryCall[0]).toBe("mock-queue-id");
984+expect(String(failDeliveryCall[1])).toContain("marker offline");
964985expect(queueMocks.ackDelivery).not.toHaveBeenCalled();
965986});
966987@@ -1553,16 +1574,14 @@ describe("deliverOutboundPayloads", () => {
15531574payloads: [{ text: "visible" }],
15541575});
155515761556-expect(normalizePayload).toHaveBeenCalledWith({
1557-accountId: "workspace-a",
1558- cfg,
1559-payload: expect.objectContaining({ text: "visible" }),
1577+const normalizeParams = requireMockCallArg(normalizePayload, "normalizePayload");
1578+expect(normalizeParams.accountId).toBe("workspace-a");
1579+expect(normalizeParams.cfg).toBe(cfg);
1580+expect((normalizeParams.payload as { text?: unknown }).text).toBe("visible");
1581+const sendParams = requireMockCallArg(sendPayload, "sendPayload");
1582+expect((sendParams.payload as { channelData?: unknown }).channelData).toEqual({
1583+normalized: true,
15601584});
1561-expect(sendPayload).toHaveBeenCalledWith(
1562-expect.objectContaining({
1563-payload: expect.objectContaining({ channelData: { normalized: true } }),
1564-}),
1565-);
15661585});
1567158615681587it("strips internal runtime scaffolding copied into rendered and normalized nested payloads", async () => {
@@ -2178,12 +2197,9 @@ describe("deliverOutboundPayloads", () => {
21782197});
2179219821802199expect(chunker).toHaveBeenCalledWith("**bold**", 4000);
2181-expect(sendText).toHaveBeenCalledWith(
2182-expect.objectContaining({
2183-text: "<b>bold</b>",
2184-formatting: { parseMode: "HTML" },
2185-}),
2186-);
2200+const sendTextParams = requireMockCallArg(sendText, "sendText");
2201+expect(sendTextParams.text).toBe("<b>bold</b>");
2202+expect(sendTextParams.formatting).toEqual({ parseMode: "HTML" });
21872203});
2188220421892205it("passes config through for plugin media sends", async () => {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。