mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-03 03:03:24 -04:00
refactor(test): dedupe onboarding gateway prompter
This commit is contained in:
@@ -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<string | undefined> }) {
|
||||
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",
|
||||
|
||||
Reference in New Issue
Block a user