refactor(test): dedupe setup wizard test helpers

This commit is contained in:
Peter Steinberger
2026-03-21 23:29:02 +00:00
parent 6266b842d4
commit 57fa59ab92
13 changed files with 222 additions and 271 deletions

View File

@@ -1,5 +1,10 @@
import { describe, expect, it, vi } from "vitest";
import { buildChannelSetupWizardAdapterFromSetupWizard } from "../../../src/channels/plugins/setup-wizard.js";
import { createRuntimeEnv } from "../../../test/helpers/extensions/runtime-env.js";
import {
createPluginSetupWizardAdapter,
createTestWizardPrompter,
runSetupWizardConfigure,
} from "../../../test/helpers/extensions/setup-wizard.js";
vi.mock("./probe.js", () => ({
probeFeishu: vi.fn(async () => ({ ok: false, error: "mocked" })),
@@ -7,13 +12,6 @@ vi.mock("./probe.js", () => ({
import { feishuPlugin } from "./channel.js";
const baseConfigureContext = {
runtime: {} as never,
accountOverrides: {},
shouldPromptAccountIds: false,
forceAllowFrom: false,
};
const baseStatusContext = {
accountOverrides: {},
};
@@ -56,10 +54,7 @@ async function getStatusWithEnvRefs(params: { appIdKey: string; appSecretKey: st
});
}
const feishuConfigureAdapter = buildChannelSetupWizardAdapterFromSetupWizard({
plugin: feishuPlugin,
wizard: feishuPlugin.setupWizard!,
});
const feishuConfigureAdapter = createPluginSetupWizardAdapter(feishuPlugin);
describe("feishu setup wizard", () => {
it("does not throw when config appId/appSecret are SecretRef objects", async () => {
@@ -68,18 +63,17 @@ describe("feishu setup wizard", () => {
.mockResolvedValueOnce("cli_from_prompt")
.mockResolvedValueOnce("secret_from_prompt")
.mockResolvedValueOnce("oc_group_1");
const prompter = {
note: vi.fn(async () => undefined),
const prompter = createTestWizardPrompter({
text,
confirm: vi.fn(async () => true),
select: vi.fn(
async ({ initialValue }: { initialValue?: string }) => initialValue ?? "allowlist",
),
} as never;
) as never,
});
await expect(
feishuConfigureAdapter.configure({
runSetupWizardConfigure({
configure: feishuConfigureAdapter.configure,
cfg: {
channels: {
feishu: {
@@ -89,7 +83,7 @@ describe("feishu setup wizard", () => {
},
} as never,
prompter,
...baseConfigureContext,
runtime: createRuntimeEnv({ throwOnExit: false }) as never,
}),
).resolves.toBeTruthy();
});