Add Vitest unit tests for auth-store Zustand state for issue 443#530
Open
parthpatidar03 wants to merge 1 commit into
Open
Add Vitest unit tests for auth-store Zustand state for issue 443#530parthpatidar03 wants to merge 1 commit into
parthpatidar03 wants to merge 1 commit into
Conversation
Author
|
@param20h plz review |
param20h
approved these changes
Jun 11, 2026
Owner
|
solve |
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.
Closes #443
📝 What does this PR do?
Adds 35 Vitest unit tests for the frontend
auth-store.tsZustand store, covering every action in the store:login()— credential login, token saving, error handlingloginWithGoogle()— Google OAuth token flowlogout()— state/localStorage clearing, network failure resilienceregister()— response data, state and localStorage cleanupinitializeAuth()— token rehydration from localStorage, 401 handling, skip-if-initialized guardsyncTokensRefreshed()— partial updates, preserves existing values, no-op on undefinedsyncLoggedOut()— cross-tab logout syncsetHfToken()— HuggingFace token updateFile added:
frontend/src/store/auth-store.test.ts🗂️ Type of Change
🧪 How was this tested?
Tests run with the existing Vitest setup (
vitest.config.ts+src/test/setup.ts), no new dependencies required.Results:
login()loginWithGoogle()logout()register()initializeAuth()syncTokensRefreshed()syncLoggedOut()setHfToken()Run tests locally:
cd frontend npx vitest run src/store/auth-store.test.ts📸 Screenshots (if UI change)
N/A — test-only change, no UI affected.
apimodule is mocked viavi.mock("@/lib/api")— no real network calls madeuseAuthStore.setState({...})to ensure full isolationlogout()is tested with both successful and failing API calls — confirms state is cleared regardless of network errors (important for UX)initializeAuth()skip-if-initialized guard is explicitly tested to prevent double-fetch bugs✅ Self-Review Checklist
dev, notmainmainbranch or any HuggingFace deployment config