From 3e7800befb928373fa33af419d7899f1fe1ec572 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sun, 15 Feb 2026 15:15:19 +0000 Subject: [PATCH] refactor(test): dedupe onboarding gateway prompter --- src/wizard/onboarding.gateway-config.test.ts | 49 +++++++++----------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/src/wizard/onboarding.gateway-config.test.ts b/src/wizard/onboarding.gateway-config.test.ts index c15f73e6e85..dee6b236a66 100644 --- a/src/wizard/onboarding.gateway-config.test.ts +++ b/src/wizard/onboarding.gateway-config.test.ts @@ -21,12 +21,11 @@ vi.mock("../infra/tailscale.js", () => ({ import { configureGatewayForOnboarding } from "./onboarding.gateway-config.js"; describe("configureGatewayForOnboarding", () => { - it("generates a token when the prompt returns undefined", async () => { - mocks.randomToken.mockReturnValue("generated-token"); + function createPrompter(params: { selectQueue: string[]; textQueue: Array }) { + const selectQueue = [...params.selectQueue]; + const textQueue = [...params.textQueue]; - const selectQueue = ["loopback", "token", "off"]; - const textQueue = ["18789", undefined]; - const prompter: WizardPrompter = { + return { intro: vi.fn(async () => {}), outro: vi.fn(async () => {}), note: vi.fn(async () => {}), @@ -35,13 +34,25 @@ describe("configureGatewayForOnboarding", () => { text: vi.fn(async () => textQueue.shift() as string), confirm: vi.fn(async () => false), progress: vi.fn(() => ({ update: vi.fn(), stop: vi.fn() })), - }; + } satisfies WizardPrompter; + } - const runtime: RuntimeEnv = { + function createRuntime(): RuntimeEnv { + return { log: vi.fn(), error: vi.fn(), exit: vi.fn(), }; + } + + it("generates a token when the prompt returns undefined", async () => { + mocks.randomToken.mockReturnValue("generated-token"); + + const prompter = createPrompter({ + selectQueue: ["loopback", "token", "off"], + textQueue: ["18789", undefined], + }); + const runtime = createRuntime(); const result = await configureGatewayForOnboarding({ flow: "advanced", @@ -77,25 +88,11 @@ describe("configureGatewayForOnboarding", () => { mocks.randomToken.mockReturnValue("unused"); // Flow: loopback bind → password auth → tailscale off - const selectQueue = ["loopback", "password", "off"]; - // Port prompt → OK, then password prompt → returns undefined - const textQueue = ["18789", undefined]; - const prompter: WizardPrompter = { - intro: vi.fn(async () => {}), - outro: vi.fn(async () => {}), - note: vi.fn(async () => {}), - select: vi.fn(async () => selectQueue.shift() as string), - multiselect: vi.fn(async () => []), - text: vi.fn(async () => textQueue.shift() as string), - confirm: vi.fn(async () => false), - progress: vi.fn(() => ({ update: vi.fn(), stop: vi.fn() })), - }; - - const runtime: RuntimeEnv = { - log: vi.fn(), - error: vi.fn(), - exit: vi.fn(), - }; + const prompter = createPrompter({ + selectQueue: ["loopback", "password", "off"], + textQueue: ["18789", undefined], + }); + const runtime = createRuntime(); const result = await configureGatewayForOnboarding({ flow: "advanced",