diff --git a/components/developer/scenario-selector.tsx b/components/developer/scenario-selector.tsx index d5438fc..fe05936 100644 --- a/components/developer/scenario-selector.tsx +++ b/components/developer/scenario-selector.tsx @@ -10,7 +10,7 @@ import { useState, useId } from "react"; import { Button } from "@/components/ui/button"; import { Select } from "@/components/ui/select"; -import { applyMockScenario, resetMockData } from "@/lib/api/mock"; +import { applyMockScenario, resetMockData } from "@/lib/api"; import { config } from "@/lib/config"; type MockScenario = diff --git a/lib/api/index.ts b/lib/api/index.ts index b1288fe..7cdfa34 100644 --- a/lib/api/index.ts +++ b/lib/api/index.ts @@ -1,15 +1,13 @@ import { config } from '../config' import { LiveAccessApi } from './live' import { - MockAccessApi, + createMockAccessApi, resetMockData, applyMockScenario, replayMockEvent, setMockRoleMutationFailure, setMockMetaVersion, - setMockResourceFetchFailure, - setMockResourceFetchDelay, -} from './mock' +} from './mock-boundary' import { AccessApi } from './types' import type { VersionCompatibility } from './version' @@ -25,7 +23,7 @@ export type { VersionCompatibility } * @param communityId Scoped community ID or slug */ export function getApi(address?: string, token?: string, communityId?: string): AccessApi { - if (config.apiMode === 'mock') return new MockAccessApi(address, communityId) + if (config.apiMode === 'mock') return createMockAccessApi(address, communityId) const api = new LiveAccessApi(address, token, communityId) // Kick off the startup version compatibility check. It resolves in the // background; callers can await api.checkVersion() for the result. @@ -41,9 +39,7 @@ export { replayMockEvent, setMockRoleMutationFailure, setMockMetaVersion, - setMockResourceFetchFailure, - setMockResourceFetchDelay, -} from './mock' +} from './mock-boundary' export { ApiError, AuthError, diff --git a/lib/api/mock-boundary.ts b/lib/api/mock-boundary.ts new file mode 100644 index 0000000..0eea141 --- /dev/null +++ b/lib/api/mock-boundary.ts @@ -0,0 +1,22 @@ +import type { AccessApi } from './types' +import { MockAccessApi } from './mock' + +/** + * Stable application-facing boundary for mock-only controls. + * + * Keep this list deliberately small. Application code should import these + * symbols from `@/lib/api`; tests of the mock implementation may continue to + * import `./mock` directly. + */ +export { + applyMockScenario, + replayMockEvent, + resetMockData, + setMockMetaVersion, + setMockRoleMutationFailure, +} from './mock' + +/** Creates the mock client without exposing its concrete implementation. */ +export function createMockAccessApi(address?: string, communityId?: string): AccessApi { + return new MockAccessApi(address, communityId) +} diff --git a/test/api-mock-boundary.test.ts b/test/api-mock-boundary.test.ts new file mode 100644 index 0000000..677d03f --- /dev/null +++ b/test/api-mock-boundary.test.ts @@ -0,0 +1,19 @@ +import assert from 'node:assert/strict' +import { test } from 'node:test' + +import { + applyMockScenario, + replayMockEvent, + resetMockData, + setMockMetaVersion, + setMockRoleMutationFailure, +} from '../lib/api' + +test('the API boundary exposes the application mock controls', () => { + assert.equal(typeof applyMockScenario, 'function') + assert.equal(typeof replayMockEvent, 'function') + assert.equal(typeof resetMockData, 'function') + assert.equal(typeof setMockMetaVersion, 'function') + assert.equal(typeof setMockRoleMutationFailure, 'function') +}) +