test: isolate qr/setup-code token env in unit tests

This commit is contained in:
Peter Steinberger
2026-02-16 14:58:31 +00:00
parent c9f2c3aef9
commit bc55ffb160
2 changed files with 21 additions and 2 deletions

View File

@@ -1,5 +1,5 @@
import { Command } from "commander";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { encodePairingSetupCode } from "../pairing/setup-code.js";
const runtime = {
@@ -30,6 +30,14 @@ const { registerQrCli } = await import("./qr-cli.js");
describe("registerQrCli", () => {
beforeEach(() => {
vi.clearAllMocks();
vi.stubEnv("OPENCLAW_GATEWAY_TOKEN", "");
vi.stubEnv("CLAWDBOT_GATEWAY_TOKEN", "");
vi.stubEnv("OPENCLAW_GATEWAY_PASSWORD", "");
vi.stubEnv("CLAWDBOT_GATEWAY_PASSWORD", "");
});
afterEach(() => {
vi.unstubAllEnvs();
});
it("prints setup code only when requested", async () => {

View File

@@ -1,7 +1,18 @@
import { describe, expect, it, vi } from "vitest";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { encodePairingSetupCode, resolvePairingSetupFromConfig } from "./setup-code.js";
describe("pairing setup code", () => {
beforeEach(() => {
vi.stubEnv("OPENCLAW_GATEWAY_TOKEN", "");
vi.stubEnv("CLAWDBOT_GATEWAY_TOKEN", "");
vi.stubEnv("OPENCLAW_GATEWAY_PASSWORD", "");
vi.stubEnv("CLAWDBOT_GATEWAY_PASSWORD", "");
});
afterEach(() => {
vi.unstubAllEnvs();
});
it("encodes payload as base64url JSON", () => {
const code = encodePairingSetupCode({
url: "wss://gateway.example.com:443",