Skip to content

tests: mock better-auth client and assert rejections in branching tests#51

Merged
weroperking merged 1 commit intomainfrom
codex/evaluate-betterbase-improvements
Mar 29, 2026
Merged

tests: mock better-auth client and assert rejections in branching tests#51
weroperking merged 1 commit intomainfrom
codex/evaluate-betterbase-improvements

Conversation

@weroperking
Copy link
Copy Markdown
Owner

@weroperking weroperking commented Mar 29, 2026

Motivation

  • Ensure the better-auth/client implementation is mocked before AuthClient is imported so auth tests run deterministically under bun:test.
  • Make branching/database tests explicitly validate error behavior when no real database is available instead of only checking for a Promise.

Description

  • Move bun:test imports to the top of packages/client/test/auth.test.ts and register mock.module("better-auth/client", ...) so createAuthClient and its methods are mocked before AuthClient is imported.
  • Remove the duplicate bun:test import and keep the MockStorage helper used by auth tests.
  • Replace expect(...).toBeInstanceOf(Promise) checks in packages/core/test/branching.test.ts with await expect(...).rejects.toThrow() for listPreviewDatabases, previewDatabaseExists, and teardownPreviewDatabase to assert they reject without a real DB.

Testing

  • Ran the auth tests with bun test packages/client/test/auth.test.ts and they passed.
  • Ran the branching tests with bun test packages/core/test/branching.test.ts and they passed.

Codex Task

Summary by CodeRabbit

  • Tests
    • Updated test assertions for authentication and database branching functionality to improve error verification accuracy.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 29, 2026

Walkthrough

Import statement reorganized in one test file to place bun:test imports at the top. Test assertions in another file changed from checking promise-ness to explicitly verifying rejected errors, removing intermediate variables.

Changes

Cohort / File(s) Summary
Test Import Reorganization
packages/client/test/auth.test.ts
Moved bun:test imports from below the mock.module() block to the file top. No test logic changed.
Test Assertion Updates
packages/core/test/branching.test.ts
Changed DatabaseBranching method tests from asserting Promise return types to awaiting calls and asserting they reject with rejects.toThrow(). Removed intermediate promise variables.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed Title accurately summarizes the main changes: mocking better-auth client in auth tests and updating branching test assertions from Promise checks to rejection assertions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/evaluate-betterbase-improvements

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/core/test/branching.test.ts`:
- Around line 398-416: Update the three test titles to match the asserted
failure behavior: change the describe/test names for listPreviewDatabases,
previewDatabaseExists, and teardownPreviewDatabase (the tests calling
dbBranching.listPreviewDatabases(),
dbBranching.previewDatabaseExists("preview_test"), and
dbBranching.teardownPreviewDatabase(...)) so they state they expect a rejection
on connection failure (e.g., "rejects when connection fails" or "throws on
connection error") instead of implying a successful return; alternatively, if
you intended to test the happy path, modify the assertions to await resolved
values rather than using rejects.toThrow().
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: e4d04716-be8a-4d76-a688-b68debabc0e6

📥 Commits

Reviewing files that changed from the base of the PR and between 7c534e7 and 7cc8bb6.

📒 Files selected for processing (2)
  • packages/client/test/auth.test.ts
  • packages/core/test/branching.test.ts

Comment on lines 398 to 416
describe("listPreviewDatabases", () => {
test("returns array of preview database names", async () => {
// Without actual DB connection, this will fail
// But we can verify it returns a promise
const promise = dbBranching.listPreviewDatabases();
expect(promise).toBeInstanceOf(Promise);
await expect(dbBranching.listPreviewDatabases()).rejects.toThrow();
});
});

describe("previewDatabaseExists", () => {
test("returns promise for checking database existence", async () => {
const promise = dbBranching.previewDatabaseExists("preview_test");
expect(promise).toBeInstanceOf(Promise);
await expect(dbBranching.previewDatabaseExists("preview_test")).rejects.toThrow();
});
});

describe("teardownPreviewDatabase", () => {
test("returns promise for teardown operation", async () => {
const promise = dbBranching.teardownPreviewDatabase(
"postgres://user:password@localhost:5432/preview_test",
);
expect(promise).toBeInstanceOf(Promise);
await expect(
dbBranching.teardownPreviewDatabase("postgres://user:password@localhost:5432/preview_test"),
).rejects.toThrow();
});
});
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Test descriptions don't match test behavior.

The test names describe happy-path behavior ("returns array", "returns promise") but the assertions verify rejection on connection failure. This is misleading when tests fail or when reading the test output.

Suggested renames
 describe("listPreviewDatabases", () => {
-	test("returns array of preview database names", async () => {
+	test("rejects when database connection fails", async () => {
 		await expect(dbBranching.listPreviewDatabases()).rejects.toThrow();
 	});
 });

 describe("previewDatabaseExists", () => {
-	test("returns promise for checking database existence", async () => {
+	test("rejects when database connection fails", async () => {
 		await expect(dbBranching.previewDatabaseExists("preview_test")).rejects.toThrow();
 	});
 });

 describe("teardownPreviewDatabase", () => {
-	test("returns promise for teardown operation", async () => {
+	test("rejects when database connection fails", async () => {
 		await expect(
 			dbBranching.teardownPreviewDatabase("postgres://user:password@localhost:5432/preview_test"),
 		).rejects.toThrow();
 	});
 });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
describe("listPreviewDatabases", () => {
test("returns array of preview database names", async () => {
// Without actual DB connection, this will fail
// But we can verify it returns a promise
const promise = dbBranching.listPreviewDatabases();
expect(promise).toBeInstanceOf(Promise);
await expect(dbBranching.listPreviewDatabases()).rejects.toThrow();
});
});
describe("previewDatabaseExists", () => {
test("returns promise for checking database existence", async () => {
const promise = dbBranching.previewDatabaseExists("preview_test");
expect(promise).toBeInstanceOf(Promise);
await expect(dbBranching.previewDatabaseExists("preview_test")).rejects.toThrow();
});
});
describe("teardownPreviewDatabase", () => {
test("returns promise for teardown operation", async () => {
const promise = dbBranching.teardownPreviewDatabase(
"postgres://user:password@localhost:5432/preview_test",
);
expect(promise).toBeInstanceOf(Promise);
await expect(
dbBranching.teardownPreviewDatabase("postgres://user:password@localhost:5432/preview_test"),
).rejects.toThrow();
});
});
describe("listPreviewDatabases", () => {
test("rejects when database connection fails", async () => {
await expect(dbBranching.listPreviewDatabases()).rejects.toThrow();
});
});
describe("previewDatabaseExists", () => {
test("rejects when database connection fails", async () => {
await expect(dbBranching.previewDatabaseExists("preview_test")).rejects.toThrow();
});
});
describe("teardownPreviewDatabase", () => {
test("rejects when database connection fails", async () => {
await expect(
dbBranching.teardownPreviewDatabase("postgres://user:password@localhost:5432/preview_test"),
).rejects.toThrow();
});
});
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/core/test/branching.test.ts` around lines 398 - 416, Update the
three test titles to match the asserted failure behavior: change the
describe/test names for listPreviewDatabases, previewDatabaseExists, and
teardownPreviewDatabase (the tests calling dbBranching.listPreviewDatabases(),
dbBranching.previewDatabaseExists("preview_test"), and
dbBranching.teardownPreviewDatabase(...)) so they state they expect a rejection
on connection failure (e.g., "rejects when connection fails" or "throws on
connection error") instead of implying a successful return; alternatively, if
you intended to test the happy path, modify the assertions to await resolved
values rather than using rejects.toThrow().

@weroperking weroperking merged commit d45ce43 into main Mar 29, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant