|
| 1 | +import { test, expect, describe, beforeEach, afterEach } from "bun:test"; |
| 2 | +import { getPlapiBaseUrl, warnIfPlatformApiUrlOverride } from "./environment.ts"; |
| 3 | +import { setMode } from "../mode.ts"; |
| 4 | +import { useCaptureLog } from "../test/lib/stubs.ts"; |
| 5 | + |
| 6 | +describe("warnIfPlatformApiUrlOverride", () => { |
| 7 | + const captured = useCaptureLog(); |
| 8 | + const original = process.env.CLERK_PLATFORM_API_URL; |
| 9 | + |
| 10 | + beforeEach(() => { |
| 11 | + setMode("human"); |
| 12 | + delete process.env.CLERK_PLATFORM_API_URL; |
| 13 | + }); |
| 14 | + |
| 15 | + afterEach(() => { |
| 16 | + setMode("human"); |
| 17 | + if (original === undefined) delete process.env.CLERK_PLATFORM_API_URL; |
| 18 | + else process.env.CLERK_PLATFORM_API_URL = original; |
| 19 | + }); |
| 20 | + |
| 21 | + test("warns in human mode when the override differs from the active env URL", () => { |
| 22 | + process.env.CLERK_PLATFORM_API_URL = "https://api.staging.example.com"; |
| 23 | + warnIfPlatformApiUrlOverride(); |
| 24 | + expect(captured.err).toContain("CLERK_PLATFORM_API_URL"); |
| 25 | + expect(captured.err).toContain("production"); |
| 26 | + }); |
| 27 | + |
| 28 | + test("does not warn when no override is set", () => { |
| 29 | + warnIfPlatformApiUrlOverride(); |
| 30 | + expect(captured.err).not.toContain("CLERK_PLATFORM_API_URL"); |
| 31 | + }); |
| 32 | + |
| 33 | + test("does not warn when the override equals the active env URL", () => { |
| 34 | + const profileUrl = getPlapiBaseUrl(); // no override set → active env URL |
| 35 | + process.env.CLERK_PLATFORM_API_URL = profileUrl; |
| 36 | + warnIfPlatformApiUrlOverride(); |
| 37 | + expect(captured.err).not.toContain("CLERK_PLATFORM_API_URL"); |
| 38 | + }); |
| 39 | + |
| 40 | + test("stays silent in agent mode to avoid corrupting machine-readable output", () => { |
| 41 | + setMode("agent"); |
| 42 | + process.env.CLERK_PLATFORM_API_URL = "https://api.staging.example.com"; |
| 43 | + warnIfPlatformApiUrlOverride(); |
| 44 | + expect(captured.err).not.toContain("CLERK_PLATFORM_API_URL"); |
| 45 | + }); |
| 46 | +}); |
0 commit comments