test: guard mattermost probe mock calls · openclaw/openclaw@44b09a3
steipete
·
2026-05-12
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -14,6 +14,19 @@ vi.mock("openclaw/plugin-sdk/ssrf-runtime", async () => {
|
14 | 14 | return { ...original, fetchWithSsrFGuard: mockFetchGuard }; |
15 | 15 | }); |
16 | 16 | |
| 17 | +function requireFirstFetchCall() { |
| 18 | +const [call] = mockFetchGuard.mock.calls; |
| 19 | +if (!call) { |
| 20 | +throw new Error("expected Mattermost probe fetch call"); |
| 21 | +} |
| 22 | +return call[0] as { |
| 23 | +url?: string; |
| 24 | +init?: { headers?: unknown; signal?: unknown }; |
| 25 | +auditContext?: string; |
| 26 | +policy?: unknown; |
| 27 | +}; |
| 28 | +} |
| 29 | + |
17 | 30 | describe("probeMattermost", () => { |
18 | 31 | beforeEach(() => { |
19 | 32 | mockFetchGuard.mockReset(); |
@@ -43,7 +56,7 @@ describe("probeMattermost", () => {
|
43 | 56 | |
44 | 57 | const result = await probeMattermost("https://mm.example.com/api/v4/", "bot-token"); |
45 | 58 | |
46 | | -const [fetchCall] = mockFetchGuard.mock.calls[0] ?? []; |
| 59 | +const fetchCall = requireFirstFetchCall(); |
47 | 60 | expect(fetchCall?.url).toBe("https://mm.example.com/api/v4/users/me"); |
48 | 61 | expect(fetchCall?.init?.headers).toStrictEqual({ Authorization: "Bearer bot-token" }); |
49 | 62 | expect(fetchCall?.init?.signal).toBeInstanceOf(AbortSignal); |
@@ -70,7 +83,7 @@ describe("probeMattermost", () => {
|
70 | 83 | |
71 | 84 | await probeMattermost("https://mm.example.com", "bot-token", 2500, true); |
72 | 85 | |
73 | | -const [fetchCall] = mockFetchGuard.mock.calls[0] ?? []; |
| 86 | +const fetchCall = requireFirstFetchCall(); |
74 | 87 | expect(fetchCall?.policy).toStrictEqual({ allowPrivateNetwork: true }); |
75 | 88 | }); |
76 | 89 | |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。