Skip to content

Commit aadb70b

Browse files
eluce2claude
andauthored
test(better-auth): add mock infrastructure for unit tests (#104)
test(better-auth): add mock infrastructure for unit tests - Move E2E tests (adapter.test.ts, migrate.test.ts) to tests/e2e/ - Create mock fetch utilities and OData response fixtures - Add unit tests for adapter operations using mocked responses - Update vitest.config.ts to exclude E2E tests - Add test:e2e script for running E2E tests separately Co-Authored-By: Claude Opus 4.5 <[email protected]> test(typegen): add mock infrastructure for unit tests (#103) ## Summary - Create layout metadata fixtures (`tests/fixtures/layout-metadata.ts`) - Add mock fetch utility for mocking FM Data API calls (`tests/utils/mock-fetch.ts`) - Move E2E tests requiring live FM server to `tests/e2e/` - Create unit tests that use mocked metadata (11 tests) - Update `vitest.config.ts` to exclude e2e tests by default - Add `test:e2e` script for running E2E tests with doppler ## Test plan - [x] `pnpm --filter @proofkit/typegen lint` passes - [x] `pnpm --filter @proofkit/typegen typecheck` passes - [x] `pnpm --filter @proofkit/typegen test` passes (11 unit tests) 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Establishes isolated unit testing with mocks and separates E2E runs across the repo. > > - **Better Auth**: Add mock OData responses and `mock-fetch` utils; create comprehensive adapter unit tests; move adapter/migrate E2E to `tests/e2e`; add `test:e2e` script; update `vitest.config.ts` to exclude E2E; small refactor in `migrate.ts` for safer type normalization and explicit FM type mapping > - **Typegen**: Add layout metadata fixtures and mock fetch utils; create unit tests using mocked metadata; move live E2E to `tests/e2e`; add `test:e2e` script; update `vitest.config.ts` to exclude E2E > - **Fmodata**: Relocate E2E tests to `tests/e2e`; update `test:e2e` to run folder > - **CLI**: Simplify `test` script to `vitest run`; update vitest config to exclude E2E-like test > - **Repo scripts**: Tweak `scripts/ralph-once.sh` workflow command > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 67a2fec. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> test(fmodata): move E2E tests to tests/e2e folder Move e2e.test.ts and schema-manager.test.ts to tests/e2e/ so they're excluded from default test runs. Update test:e2e script to run entire e2e folder. Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 6dba78e commit aadb70b

22 files changed

+2002
-430
lines changed

packages/better-auth/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"main": "dist/esm/index.js",
77
"scripts": {
88
"dev": "pnpm build:watch",
9-
"test": "doppler run -c test_betterauth -- vitest run",
9+
"test": "vitest run",
10+
"test:e2e": "doppler run -c test_betterauth -- vitest run tests/e2e",
1011
"typecheck": "tsc --noEmit",
1112
"build": "vite build && publint --strict",
1213
"build:watch": "vite build --watch",

packages/better-auth/src/migrate.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@ import type { createRawFetch } from "./odata";
88
type BetterAuthSchema = Record<string, { fields: Record<string, DBFieldAttribute>; order: number }>;
99

1010
function normalizeBetterAuthFieldType(fieldType: unknown): string {
11-
if (typeof fieldType === "string") return fieldType;
12-
if (Array.isArray(fieldType)) return fieldType.map(String).join("|");
11+
if (typeof fieldType === "string") {
12+
return fieldType;
13+
}
14+
if (Array.isArray(fieldType)) {
15+
return fieldType.map(String).join("|");
16+
}
1317
return String(fieldType);
1418
}
1519

@@ -106,8 +110,12 @@ export async function planMigration(
106110
// Normalize it to a string so our FM mapping logic remains stable.
107111
// Use .includes() for all checks to handle array types like ["boolean", "null"] → "boolean|null"
108112
const t = normalizeBetterAuthFieldType(field.type);
109-
const type: "varchar" | "numeric" | "timestamp" =
110-
t.includes("boolean") || t.includes("number") ? "numeric" : t.includes("date") ? "timestamp" : "varchar";
113+
let type: "varchar" | "numeric" | "timestamp" = "varchar";
114+
if (t.includes("boolean") || t.includes("number")) {
115+
type = "numeric";
116+
} else if (t.includes("date")) {
117+
type = "timestamp";
118+
}
111119
return {
112120
name: field.fieldName ?? key,
113121
type,

0 commit comments

Comments
 (0)