test: guard discord component mock calls · openclaw/openclaw@d970a81
steipete
·
2026-05-12
·
via Recent Commits to openclaw:main
File tree
extensions/discord/src/monitor
| Original file line number | Diff line number | Diff line change |
|---|
@@ -73,6 +73,22 @@ describe("agent components", () => {
|
73 | 73 | }; |
74 | 74 | }; |
75 | 75 | |
| 76 | +const firstReplyContent = (reply: ReturnType<typeof vi.fn>): string => { |
| 77 | +const [call] = reply.mock.calls; |
| 78 | +if (!call) { |
| 79 | +throw new Error("expected interaction reply call"); |
| 80 | +} |
| 81 | +const [payload] = call; |
| 82 | +if (!payload || typeof payload !== "object" || !("content" in payload)) { |
| 83 | +throw new Error("expected interaction reply content"); |
| 84 | +} |
| 85 | +const { content } = payload as { content?: unknown }; |
| 86 | +if (typeof content !== "string") { |
| 87 | +throw new Error("expected interaction reply content to be a string"); |
| 88 | +} |
| 89 | +return content; |
| 90 | +}; |
| 91 | + |
76 | 92 | const createBaseGroupDmInteraction = (overrides: Record<string, unknown> = {}) => { |
77 | 93 | const reply = vi.fn().mockResolvedValue(undefined); |
78 | 94 | const defer = vi.fn().mockResolvedValue(undefined); |
@@ -151,7 +167,7 @@ describe("agent components", () => {
|
151 | 167 | |
152 | 168 | expect(defer).not.toHaveBeenCalled(); |
153 | 169 | expect(reply).toHaveBeenCalledTimes(1); |
154 | | -const pairingText = String(reply.mock.calls[0]?.[0]?.content ?? ""); |
| 170 | +const pairingText = firstReplyContent(reply); |
155 | 171 | const code = expectPairingReplyText(pairingText, { |
156 | 172 | channel: "discord", |
157 | 173 | idLine: "Your Discord user id: 123456789", |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。