[PR #8430] test: add regression tests for #8156 (secondaryStorage with auto-deserialized JSON) #16212

Open
opened 2026-04-13 10:26:39 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/8430
Author: @himself65
Created: 3/5/2026
Status: 🔄 Open

Base: mainHead: fix/close-8156-regression-test


📝 Commits (1)

  • 85976c2 test: add regression tests for #8156 (secondaryStorage with auto-deserialized JSON)

📊 Changes

2 files changed (+106 additions, -0 deletions)

View changed files

📝 packages/better-auth/src/api/routes/update-user.test.ts (+44 -0)
📝 packages/better-auth/src/db/internal-adapter.test.ts (+62 -0)

📄 Description

Summary

Closes #8156

The root cause of this issue was already fixed in #8248 (reviveDates in safeJSONParse), which correctly converts ISO 8601 date strings back to Date instances when secondary storage (e.g. @vercel/kv) returns already-parsed objects instead of strings.

This PR adds regression tests to prevent the issue from recurring:

  • Adapter-level test (internal-adapter.test.ts): Simulates @vercel/kv behavior where get() returns a parsed object. Verifies that updateUser and updateUserByEmail correctly refresh sessions without crashing on expiresAt.getTime().
  • Route-level test (update-user.test.ts): End-to-end test via the auth client confirming that updateUser propagates changes and sessions remain valid when secondary storage auto-deserializes JSON.

Both tests verify the precondition (typeof expiresAt === "string" in the store) before exercising the code path that previously crashed.

Test plan

  • npx vitest packages/better-auth/src/db/internal-adapter.test.ts --run — 34 tests pass
  • npx vitest packages/better-auth/src/api/routes/update-user.test.ts --run — 22 tests pass
  • biome check passes on changed files

🔄 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/8430 **Author:** [@himself65](https://github.com/himself65) **Created:** 3/5/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/close-8156-regression-test` --- ### 📝 Commits (1) - [`85976c2`](https://github.com/better-auth/better-auth/commit/85976c2f2bbac0d8b514f267665d0ea711dcdfb7) test: add regression tests for #8156 (secondaryStorage with auto-deserialized JSON) ### 📊 Changes **2 files changed** (+106 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/api/routes/update-user.test.ts` (+44 -0) 📝 `packages/better-auth/src/db/internal-adapter.test.ts` (+62 -0) </details> ### 📄 Description ## Summary Closes #8156 The root cause of this issue was already fixed in #8248 (`reviveDates` in `safeJSONParse`), which correctly converts ISO 8601 date strings back to `Date` instances when secondary storage (e.g. `@vercel/kv`) returns already-parsed objects instead of strings. This PR adds regression tests to prevent the issue from recurring: - **Adapter-level test** (`internal-adapter.test.ts`): Simulates `@vercel/kv` behavior where `get()` returns a parsed object. Verifies that `updateUser` and `updateUserByEmail` correctly refresh sessions without crashing on `expiresAt.getTime()`. - **Route-level test** (`update-user.test.ts`): End-to-end test via the auth client confirming that `updateUser` propagates changes and sessions remain valid when secondary storage auto-deserializes JSON. Both tests verify the precondition (`typeof expiresAt === "string"` in the store) before exercising the code path that previously crashed. ## Test plan - [x] `npx vitest packages/better-auth/src/db/internal-adapter.test.ts --run` — 34 tests pass - [x] `npx vitest packages/better-auth/src/api/routes/update-user.test.ts --run` — 22 tests pass - [x] `biome check` passes on changed files --- <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-04-13 10:26:39 -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#16212