mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 02:22:43 +00: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";
|
import { configureGatewayForOnboarding } from "./onboarding.gateway-config.js";
|
||||||
|
|
||||||
describe("configureGatewayForOnboarding", () => {
|
describe("configureGatewayForOnboarding", () => {
|
||||||
it("generates a token when the prompt returns undefined", async () => {
|
function createPrompter(params: { selectQueue: string[]; textQueue: Array<string | undefined> }) {
|
||||||
mocks.randomToken.mockReturnValue("generated-token");
|
const selectQueue = [...params.selectQueue];
|
||||||
|
const textQueue = [...params.textQueue];
|
||||||
|
|
||||||
const selectQueue = ["loopback", "token", "off"];
|
return {
|
||||||
const textQueue = ["18789", undefined];
|
|
||||||
const prompter: WizardPrompter = {
|
|
||||||
intro: vi.fn(async () => {}),
|
intro: vi.fn(async () => {}),
|
||||||
outro: vi.fn(async () => {}),
|
outro: vi.fn(async () => {}),
|
||||||
note: vi.fn(async () => {}),
|
note: vi.fn(async () => {}),
|
||||||
@@ -35,13 +34,25 @@ describe("configureGatewayForOnboarding", () => {
|
|||||||
text: vi.fn(async () => textQueue.shift() as string),
|
text: vi.fn(async () => textQueue.shift() as string),
|
||||||
confirm: vi.fn(async () => false),
|
confirm: vi.fn(async () => false),
|
||||||
progress: vi.fn(() => ({ update: vi.fn(), stop: vi.fn() })),
|
progress: vi.fn(() => ({ update: vi.fn(), stop: vi.fn() })),
|
||||||
};
|
} satisfies WizardPrompter;
|
||||||
|
}
|
||||||
|
|
||||||
const runtime: RuntimeEnv = {
|
function createRuntime(): RuntimeEnv {
|
||||||
|
return {
|
||||||
log: vi.fn(),
|
log: vi.fn(),
|
||||||
error: vi.fn(),
|
error: vi.fn(),
|
||||||
exit: 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({
|
const result = await configureGatewayForOnboarding({
|
||||||
flow: "advanced",
|
flow: "advanced",
|
||||||
@@ -77,25 +88,11 @@ describe("configureGatewayForOnboarding", () => {
|
|||||||
mocks.randomToken.mockReturnValue("unused");
|
mocks.randomToken.mockReturnValue("unused");
|
||||||
|
|
||||||
// Flow: loopback bind → password auth → tailscale off
|
// Flow: loopback bind → password auth → tailscale off
|
||||||
const selectQueue = ["loopback", "password", "off"];
|
const prompter = createPrompter({
|
||||||
// Port prompt → OK, then password prompt → returns undefined
|
selectQueue: ["loopback", "password", "off"],
|
||||||
const textQueue = ["18789", undefined];
|
textQueue: ["18789", undefined],
|
||||||
const prompter: WizardPrompter = {
|
});
|
||||||
intro: vi.fn(async () => {}),
|
const runtime = createRuntime();
|
||||||
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 result = await configureGatewayForOnboarding({
|
const result = await configureGatewayForOnboarding({
|
||||||
flow: "advanced",
|
flow: "advanced",
|
||||||
|
|||||||
Reference in New Issue
Block a user