refactor(tests): share setup wizard prompter

This commit is contained in:
Peter Steinberger
2026-03-17 06:29:38 +00:00
parent cc35627c8f
commit d28cb8d821
9 changed files with 52 additions and 180 deletions

View File

@@ -1,31 +1,10 @@
import type { OpenClawConfig, WizardPrompter } from "openclaw/plugin-sdk/googlechat";
import type { OpenClawConfig } from "openclaw/plugin-sdk/googlechat";
import { describe, expect, it, vi } from "vitest";
import { buildChannelSetupWizardAdapterFromSetupWizard } from "../../../src/channels/plugins/setup-wizard.js";
import { createRuntimeEnv } from "../../test-utils/runtime-env.js";
import { createTestWizardPrompter, type WizardPrompter } from "../../test-utils/setup-wizard.js";
import { googlechatPlugin } from "./channel.js";
const selectFirstOption = async <T>(params: { options: Array<{ value: T }> }): Promise<T> => {
const first = params.options[0];
if (!first) {
throw new Error("no options");
}
return first.value;
};
function createPrompter(overrides: Partial<WizardPrompter>): WizardPrompter {
return {
intro: vi.fn(async () => {}),
outro: vi.fn(async () => {}),
note: vi.fn(async () => {}),
select: selectFirstOption as WizardPrompter["select"],
multiselect: vi.fn(async () => []),
text: vi.fn(async () => "") as WizardPrompter["text"],
confirm: vi.fn(async () => false),
progress: vi.fn(() => ({ update: vi.fn(), stop: vi.fn() })),
...overrides,
};
}
const googlechatConfigureAdapter = buildChannelSetupWizardAdapterFromSetupWizard({
plugin: googlechatPlugin,
wizard: googlechatPlugin.setupWizard!,
@@ -33,7 +12,7 @@ const googlechatConfigureAdapter = buildChannelSetupWizardAdapterFromSetupWizard
describe("googlechat setup wizard", () => {
it("configures service-account auth and webhook audience", async () => {
const prompter = createPrompter({
const prompter = createTestWizardPrompter({
text: vi.fn(async ({ message }: { message: string }) => {
if (message === "Service account JSON path") {
return "/tmp/googlechat-service-account.json";