[PR #4714] [MERGED] test: add runWithDefaultUser helper #5544

Closed
opened 2026-03-13 12:26:43 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/4714
Author: @himself65
Created: 9/17/2025
Status: Merged
Merged: 9/17/2025
Merged by: @himself65

Base: canaryHead: himself65/2025/09/16/als-test


📝 Commits (2)

📊 Changes

9 files changed (+537 additions, -599 deletions)

View changed files

📝 docs/content/docs/reference/contributing.mdx (+22 -1)
📝 packages/better-auth/src/api/routes/account.test.ts (+218 -253)
📝 packages/better-auth/src/api/routes/email-verification.test.ts (+37 -38)
📝 packages/better-auth/src/api/routes/reset-password.test.ts (+19 -25)
📝 packages/better-auth/src/api/routes/session-api.test.ts (+61 -89)
📝 packages/better-auth/src/api/routes/sign-out.test.ts (+6 -8)
📝 packages/better-auth/src/api/routes/update-user.test.ts (+109 -165)
📝 packages/better-auth/src/social-providers/social.test.ts (+2 -2)
📝 packages/better-auth/src/test-utils/test-instance.ts (+63 -18)

📄 Description

Summary by cubic

Refactored tests to use a new runWithDefaultUserClient helper that auto-injects auth headers via AsyncLocalStorage, removing boilerplate and making tests clearer and more reliable. Updated customFetchImpl to merge stored headers and apply them to all client calls.

  • Refactors
    • Added AsyncLocalStorage-backed current user context in test-utils.
    • Introduced runWithDefaultUserClient and runWithClient helpers to run client calls with the signed-in user’s headers.
    • Updated customFetchImpl to merge context headers with request headers before calling auth.handler.
    • Migrated tests across routes and plugins (accounts, sessions, email verification, reset password, update user, sign-out, admin, jwt, passkey, username, additional-fields) to use the new helpers and drop manual header passing.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/4714 **Author:** [@himself65](https://github.com/himself65) **Created:** 9/17/2025 **Status:** ✅ Merged **Merged:** 9/17/2025 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `himself65/2025/09/16/als-test` --- ### 📝 Commits (2) - [`c7fd165`](https://github.com/better-auth/better-auth/commit/c7fd165a873580e735dc9a8cca85fefea76451dc) feat: refactor test - [`5529717`](https://github.com/better-auth/better-auth/commit/5529717a1e04a1d726f3905b1f0411f514a297da) docs: update ### 📊 Changes **9 files changed** (+537 additions, -599 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/reference/contributing.mdx` (+22 -1) 📝 `packages/better-auth/src/api/routes/account.test.ts` (+218 -253) 📝 `packages/better-auth/src/api/routes/email-verification.test.ts` (+37 -38) 📝 `packages/better-auth/src/api/routes/reset-password.test.ts` (+19 -25) 📝 `packages/better-auth/src/api/routes/session-api.test.ts` (+61 -89) 📝 `packages/better-auth/src/api/routes/sign-out.test.ts` (+6 -8) 📝 `packages/better-auth/src/api/routes/update-user.test.ts` (+109 -165) 📝 `packages/better-auth/src/social-providers/social.test.ts` (+2 -2) 📝 `packages/better-auth/src/test-utils/test-instance.ts` (+63 -18) </details> ### 📄 Description <!-- This is an auto-generated description by cubic. --> ## Summary by cubic Refactored tests to use a new runWithDefaultUserClient helper that auto-injects auth headers via AsyncLocalStorage, removing boilerplate and making tests clearer and more reliable. Updated customFetchImpl to merge stored headers and apply them to all client calls. - **Refactors** - Added AsyncLocalStorage-backed current user context in test-utils. - Introduced runWithDefaultUserClient and runWithClient helpers to run client calls with the signed-in user’s headers. - Updated customFetchImpl to merge context headers with request headers before calling auth.handler. - Migrated tests across routes and plugins (accounts, sessions, email verification, reset password, update user, sign-out, admin, jwt, passkey, username, additional-fields) to use the new helpers and drop manual header passing. <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-03-13 12:26:43 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#5544