test: guard webhooks mock calls · openclaw/openclaw@9a9dc4a
steipete
·
2026-05-12
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -32,6 +32,14 @@ function createApi(params?: {
|
32 | 32 | }); |
33 | 33 | } |
34 | 34 | |
| 35 | +function requireFirstRouteRegistration(mock: ReturnType<typeof vi.fn>) { |
| 36 | +const [call] = mock.mock.calls; |
| 37 | +if (!call) { |
| 38 | +throw new Error("expected webhook route registration"); |
| 39 | +} |
| 40 | +return call[0] as Parameters<OpenClawPluginApi["registerHttpRoute"]>[0]; |
| 41 | +} |
| 42 | + |
35 | 43 | describe("webhooks plugin registration", () => { |
36 | 44 | it("registers SecretRef-backed routes synchronously", () => { |
37 | 45 | const registerHttpRoute = vi.fn(); |
@@ -56,11 +64,11 @@ describe("webhooks plugin registration", () => {
|
56 | 64 | |
57 | 65 | expect(result).toBeUndefined(); |
58 | 66 | expect(registerHttpRoute).toHaveBeenCalledTimes(1); |
59 | | -const route = registerHttpRoute.mock.calls[0]?.[0]; |
60 | | -expect(route?.path).toBe("/plugins/webhooks/zapier"); |
61 | | -expect(route?.auth).toBe("plugin"); |
62 | | -expect(route?.match).toBe("exact"); |
63 | | -expect(route?.replaceExisting).toBe(true); |
64 | | -expect(route?.handler).toBeTypeOf("function"); |
| 67 | +const route = requireFirstRouteRegistration(registerHttpRoute); |
| 68 | +expect(route.path).toBe("/plugins/webhooks/zapier"); |
| 69 | +expect(route.auth).toBe("plugin"); |
| 70 | +expect(route.match).toBe("exact"); |
| 71 | +expect(route.replaceExisting).toBe(true); |
| 72 | +expect(route.handler).toBeTypeOf("function"); |
65 | 73 | }); |
66 | 74 | }); |
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。