mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 22:08:26 +00:00
fix: local updates for PR #4873
Co-authored-by: Hisleren <Hisleren@users.noreply.github.com>
This commit is contained in:
committed by
Gustavo Madeira Santana
parent
201d7fa956
commit
e5a95b5b66
74
src/commands/configure.gateway.test.ts
Normal file
74
src/commands/configure.gateway.test.ts
Normal file
@@ -0,0 +1,74 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
import type { RuntimeEnv } from "../runtime.js";
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
text: vi.fn(),
|
||||
select: vi.fn(),
|
||||
confirm: vi.fn(),
|
||||
resolveGatewayPort: vi.fn(),
|
||||
buildGatewayAuthConfig: vi.fn(),
|
||||
note: vi.fn(),
|
||||
randomToken: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("../config/config.js", async (importActual) => {
|
||||
const actual = await importActual<typeof import("../config/config.js")>();
|
||||
return {
|
||||
...actual,
|
||||
resolveGatewayPort: mocks.resolveGatewayPort,
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("./configure.shared.js", () => ({
|
||||
text: mocks.text,
|
||||
select: mocks.select,
|
||||
confirm: mocks.confirm,
|
||||
}));
|
||||
|
||||
vi.mock("../terminal/note.js", () => ({
|
||||
note: mocks.note,
|
||||
}));
|
||||
|
||||
vi.mock("./configure.gateway-auth.js", () => ({
|
||||
buildGatewayAuthConfig: mocks.buildGatewayAuthConfig,
|
||||
}));
|
||||
|
||||
vi.mock("../infra/tailscale.js", () => ({
|
||||
findTailscaleBinary: vi.fn(async () => undefined),
|
||||
}));
|
||||
|
||||
vi.mock("./onboard-helpers.js", async (importActual) => {
|
||||
const actual = await importActual<typeof import("./onboard-helpers.js")>();
|
||||
return {
|
||||
...actual,
|
||||
randomToken: mocks.randomToken,
|
||||
};
|
||||
});
|
||||
|
||||
import { promptGatewayConfig } from "./configure.gateway.js";
|
||||
|
||||
describe("promptGatewayConfig", () => {
|
||||
it("generates a token when the prompt returns undefined", async () => {
|
||||
mocks.resolveGatewayPort.mockReturnValue(18789);
|
||||
const selectQueue = ["loopback", "token", "off"];
|
||||
mocks.select.mockImplementation(async () => selectQueue.shift());
|
||||
const textQueue = ["18789", undefined];
|
||||
mocks.text.mockImplementation(async () => textQueue.shift());
|
||||
mocks.randomToken.mockReturnValue("generated-token");
|
||||
mocks.buildGatewayAuthConfig.mockImplementation(({ mode, token, password }) => ({
|
||||
mode,
|
||||
token,
|
||||
password,
|
||||
}));
|
||||
|
||||
const runtime: RuntimeEnv = {
|
||||
log: vi.fn(),
|
||||
error: vi.fn(),
|
||||
exit: vi.fn(),
|
||||
};
|
||||
|
||||
const result = await promptGatewayConfig({}, runtime);
|
||||
expect(result.token).toBe("generated-token");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user