mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 09:10:45 +00:00
69 lines
1.9 KiB
TypeScript
69 lines
1.9 KiB
TypeScript
import { createTestPluginApi } from "openclaw/plugin-sdk/plugin-test-api";
|
|
import { describe, expect, it, vi } from "vitest";
|
|
import type { OpenClawPluginApi } from "./api.js";
|
|
import plugin from "./index.js";
|
|
|
|
function createApi(params?: {
|
|
pluginConfig?: OpenClawPluginApi["pluginConfig"];
|
|
registerHttpRoute?: OpenClawPluginApi["registerHttpRoute"];
|
|
logger?: OpenClawPluginApi["logger"];
|
|
}): OpenClawPluginApi {
|
|
return createTestPluginApi({
|
|
id: "webhooks",
|
|
name: "Webhooks",
|
|
source: "test",
|
|
pluginConfig: params?.pluginConfig ?? {},
|
|
runtime: {
|
|
tasks: {
|
|
managedFlows: {
|
|
bindSession: vi.fn(({ sessionKey }: { sessionKey: string }) => ({ sessionKey })),
|
|
},
|
|
},
|
|
} as unknown as OpenClawPluginApi["runtime"],
|
|
registerHttpRoute: params?.registerHttpRoute ?? vi.fn(),
|
|
logger:
|
|
params?.logger ??
|
|
({
|
|
info: vi.fn(),
|
|
warn: vi.fn(),
|
|
error: vi.fn(),
|
|
debug: vi.fn(),
|
|
} as OpenClawPluginApi["logger"]),
|
|
});
|
|
}
|
|
|
|
describe("webhooks plugin registration", () => {
|
|
it("registers SecretRef-backed routes synchronously", () => {
|
|
const registerHttpRoute = vi.fn();
|
|
|
|
const result = plugin.register(
|
|
createApi({
|
|
pluginConfig: {
|
|
routes: {
|
|
zapier: {
|
|
sessionKey: "agent:main:main",
|
|
secret: {
|
|
source: "env",
|
|
provider: "default",
|
|
id: "OPENCLAW_WEBHOOK_SECRET",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
registerHttpRoute,
|
|
}),
|
|
);
|
|
|
|
expect(result).toBeUndefined();
|
|
expect(registerHttpRoute).toHaveBeenCalledTimes(1);
|
|
expect(registerHttpRoute).toHaveBeenCalledWith(
|
|
expect.objectContaining({
|
|
path: "/plugins/webhooks/zapier",
|
|
auth: "plugin",
|
|
match: "exact",
|
|
replaceExisting: true,
|
|
}),
|
|
);
|
|
});
|
|
});
|