diff --git a/__tests__/components/OptionBadge.test.tsx b/__tests__/components/OptionBadge.test.tsx index ef7c120..2ae9573 100644 --- a/__tests__/components/OptionBadge.test.tsx +++ b/__tests__/components/OptionBadge.test.tsx @@ -14,7 +14,7 @@ import type { FieldDefinition } from "~/components/renderers/types"; describe("OptionBadge", () => { const statusField: FieldDefinition = { name: "status", - type: "status", + type: "select", options: [ { value: "completed", label: "Completed", color: "#10B981" }, { value: "blocked", label: "Blocked", color: "red" }, diff --git a/__tests__/lib/objectstack.test.ts b/__tests__/lib/objectstack.test.ts index a8e18f3..c5e7b96 100644 --- a/__tests__/lib/objectstack.test.ts +++ b/__tests__/lib/objectstack.test.ts @@ -2,7 +2,11 @@ * Tests for objectstack — client factory */ import { ObjectStackClient } from "@objectstack/client"; -import { createObjectStackClient, objectStackClient } from "~/lib/objectstack"; +import { + createObjectStackClient, + getObjectStackClient, + setObjectStackApiUrl, +} from "~/lib/objectstack"; describe("createObjectStackClient", () => { it("creates a client with token", () => { @@ -20,8 +24,21 @@ describe("createObjectStackClient", () => { }); }); -describe("objectStackClient", () => { - it("is defined", () => { - expect(objectStackClient).toBeDefined(); +describe("getObjectStackClient", () => { + // Guards against the split-brain bug a frozen module-level singleton caused: + // it must always build against the *currently-configured* URL so a server + // switch can't leave a client talking to the old host. + it("always builds against the current API URL after a server switch", () => { + setObjectStackApiUrl("https://server-a.example"); + getObjectStackClient(); + expect(ObjectStackClient).toHaveBeenLastCalledWith( + expect.objectContaining({ baseUrl: "https://server-a.example" }), + ); + + setObjectStackApiUrl("https://server-b.example"); + getObjectStackClient(); + expect(ObjectStackClient).toHaveBeenLastCalledWith( + expect.objectContaining({ baseUrl: "https://server-b.example" }), + ); }); }); diff --git a/lib/objectstack.ts b/lib/objectstack.ts index ce338a7..b8db2a6 100644 --- a/lib/objectstack.ts +++ b/lib/objectstack.ts @@ -164,8 +164,18 @@ export function apiFetch(pathOrUrl: string, init?: RequestInit): Promise