Add unit tests for Zustand stores and hooks, fix walletError stale cl… - #503
Merged
DeFiVC merged 1 commit intoSep 28, 2026
Merged
Conversation
…osure, add Secure flag to session cookie - Add comprehensive unit tests for auth-store, course-store, error-store - Add unit tests for 10 hooks without test coverage - Fix stale closure over walletError in useAuth connectWallet (ChainLearnOfficial#480) - Add Secure flag to session cookie in auth-store (ChainLearnOfficial#481) - Close ChainLearnOfficial#478, ChainLearnOfficial#479, ChainLearnOfficial#480, ChainLearnOfficial#481
|
@designsage8 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
❌ Deploy Preview for chainlearn failed.
|
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Testing and Bug Fixes
This PR addresses multiple issues related to test coverage and bug fixes in the chainlearn-frontend project.
Changes
Task #478: Add unit tests for Zustand stores
Created
src/store/__tests__/auth-store.test.ts- Comprehensive tests for auth-store including:Created
src/store/__tests__/course-store.test.ts- Comprehensive tests for course-store including:Created
src/store/__tests__/error-store.test.ts- Comprehensive tests for error-store including:Task #479: Add missing tests for hooks without test coverage
src/lib/hooks/use-previous.test.tsx- Tests for previous value trackingsrc/lib/hooks/use-unmount.test.tsx- Tests for unmount callbacksrc/lib/hooks/use-mount.test.tsx- Tests for mount callbacksrc/lib/hooks/use-boolean.test.tsx- Tests for boolean state helpersrc/lib/hooks/use-swipe.test.tsx- Tests for swipe gesture detectionsrc/lib/hooks/use-click-outside.test.tsx- Tests for click outside detectionsrc/lib/hooks/use-sessions.test.tsx- Tests for user session managementsrc/lib/hooks/use-credentials.test.tsx- Tests for credential fetching and displaysrc/lib/hooks/use-rewards.test.tsx- Tests for reward fetching and claimingsrc/lib/hooks/use-notifications.test.tsx- Tests for notification fetching and marking as readTask #480: Fix stale closure over walletError in useAuth connectWallet
File:
src/lib/hooks/use-auth.tsProblem: The
connectWalletcallback includedwalletErrorin its dependency array, but reads it inside the catch block. SincewalletErroris state, the closure captures a stale value.Solution:
walletErrorRefto track the latestwalletErrorvaluewalletErrorRef.currentinstead ofwalletErrorwalletErrorfrom theconnectWalletdependency arrayTask #481: Add Secure flag to session cookie in auth-store
File:
src/store/auth-store.tsProblem: The
setSessionCookiefunction sets thechainlearn-sessioncookie without theSecureflag, allowing JWT transmission over unencrypted HTTP.Solution:
window.location.protocol; Secureflag when served over HTTPSTesting
All new tests follow existing patterns from the codebase (e.g.,
use-debounce.test.tsx) and cover:Run tests with:
npm testType Checking
Run type checking to verify no type errors:
Branch Instructions
To create a branch and push these changes:
Then create a pull request using the GitHub UI or CLI with the title:
And include this description in the PR body.
Closes #478,
Closes #479,
Closes #480,
Closes #481