2026-03-16 01:05:06 +00:00
|
|
|
import { describe, expect, it, vi } from "vitest";
|
2026-03-17 00:59:16 -07:00
|
|
|
import { createTestPluginApi } from "../../test/helpers/extensions/plugin-api.js";
|
2026-03-16 01:05:06 +00:00
|
|
|
import plugin from "./index.js";
|
2026-03-18 23:30:25 +00:00
|
|
|
import type { OpenClawPluginApi } from "./runtime-api.js";
|
2026-03-16 01:05:06 +00:00
|
|
|
|
|
|
|
|
function createApi(
|
|
|
|
|
registrationMode: OpenClawPluginApi["registrationMode"],
|
|
|
|
|
registerHttpRoute = vi.fn(),
|
|
|
|
|
): OpenClawPluginApi {
|
|
|
|
|
return createTestPluginApi({
|
|
|
|
|
id: "mattermost",
|
|
|
|
|
name: "Mattermost",
|
|
|
|
|
source: "test",
|
|
|
|
|
config: {},
|
|
|
|
|
runtime: {} as OpenClawPluginApi["runtime"],
|
|
|
|
|
registrationMode,
|
|
|
|
|
registerHttpRoute,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
describe("mattermost plugin register", () => {
|
|
|
|
|
it("skips slash callback registration in setup-only mode", () => {
|
|
|
|
|
const registerHttpRoute = vi.fn();
|
|
|
|
|
|
|
|
|
|
plugin.register(createApi("setup-only", registerHttpRoute));
|
|
|
|
|
|
|
|
|
|
expect(registerHttpRoute).not.toHaveBeenCalled();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("registers slash callback routes in full mode", () => {
|
|
|
|
|
const registerHttpRoute = vi.fn();
|
|
|
|
|
|
|
|
|
|
plugin.register(createApi("full", registerHttpRoute));
|
|
|
|
|
|
|
|
|
|
expect(registerHttpRoute).toHaveBeenCalledTimes(1);
|
|
|
|
|
expect(registerHttpRoute).toHaveBeenCalledWith(
|
|
|
|
|
expect.objectContaining({
|
|
|
|
|
path: "/api/channels/mattermost/command",
|
|
|
|
|
auth: "plugin",
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
});
|