refactor(test): dedupe command config and model test fixtures

This commit is contained in:
Peter Steinberger
2026-02-16 16:32:11 +00:00
parent 130e59a9c0
commit 261f5ee492
6 changed files with 273 additions and 363 deletions

View File

@@ -1,6 +1,18 @@
import { describe, expect, it } from "vitest";
import { buildGatewayAuthConfig } from "./configure.js";
function expectGeneratedTokenFromInput(token: string | undefined, literalToAvoid = "undefined") {
const result = buildGatewayAuthConfig({
mode: "token",
token,
});
expect(result?.mode).toBe("token");
expect(result?.token).toBeDefined();
expect(result?.token).not.toBe(literalToAvoid);
expect(typeof result?.token).toBe("string");
expect(result?.token?.length).toBeGreaterThan(0);
}
describe("buildGatewayAuthConfig", () => {
it("preserves allowTailscale when switching to token", () => {
const result = buildGatewayAuthConfig({
@@ -54,68 +66,23 @@ describe("buildGatewayAuthConfig", () => {
});
it("generates random token when token param is undefined", () => {
const result = buildGatewayAuthConfig({
mode: "token",
token: undefined,
});
expect(result?.mode).toBe("token");
expect(result?.token).toBeDefined();
expect(result?.token).not.toBe("undefined");
expect(typeof result?.token).toBe("string");
expect(result?.token?.length).toBeGreaterThan(0);
expectGeneratedTokenFromInput(undefined);
});
it("generates random token when token param is empty string", () => {
const result = buildGatewayAuthConfig({
mode: "token",
token: "",
});
expect(result?.mode).toBe("token");
expect(result?.token).toBeDefined();
expect(result?.token).not.toBe("undefined");
expect(typeof result?.token).toBe("string");
expect(result?.token?.length).toBeGreaterThan(0);
expectGeneratedTokenFromInput("");
});
it("generates random token when token param is whitespace only", () => {
const result = buildGatewayAuthConfig({
mode: "token",
token: " ",
});
expect(result?.mode).toBe("token");
expect(result?.token).toBeDefined();
expect(result?.token).not.toBe("undefined");
expect(typeof result?.token).toBe("string");
expect(result?.token?.length).toBeGreaterThan(0);
expectGeneratedTokenFromInput(" ");
});
it('generates random token when token param is the literal string "undefined"', () => {
const result = buildGatewayAuthConfig({
mode: "token",
token: "undefined",
});
expect(result?.mode).toBe("token");
expect(result?.token).toBeDefined();
expect(result?.token).not.toBe("undefined");
expect(typeof result?.token).toBe("string");
expect(result?.token?.length).toBeGreaterThan(0);
expectGeneratedTokenFromInput("undefined");
});
it('generates random token when token param is the literal string "null"', () => {
const result = buildGatewayAuthConfig({
mode: "token",
token: "null",
});
expect(result?.mode).toBe("token");
expect(result?.token).toBeDefined();
expect(result?.token).not.toBe("null");
expect(typeof result?.token).toBe("string");
expect(result?.token?.length).toBeGreaterThan(0);
expectGeneratedTokenFromInput("null", "null");
});
it("builds trusted-proxy config with all options", () => {