Skip to content

test(frontend): add Vitest unit tests for auth-store#666

Merged
param20h merged 2 commits into
param20h:devfrom
nancysangani:feat/auth-store-tests
Jun 23, 2026
Merged

test(frontend): add Vitest unit tests for auth-store#666
param20h merged 2 commits into
param20h:devfrom
nancysangani:feat/auth-store-tests

Conversation

@nancysangani

Copy link
Copy Markdown
Contributor

Closes #443

📝 What does this PR do?

Adds Vitest unit tests for the Zustand useAuthStore covering all state
transitions and actions.

New file: frontend/src/store/auth-store.test.ts

The api module is fully mocked with vi.mock so no real network calls
are made. The store is reset to a clean initial state before every test
via useAuthStore.setState + localStorage.clear().

🗂️ Type of Change

  • 🧪 Tests

🧪 Tests added (27 total)

Group Test
initial state starts with null user/token when localStorage empty
initial state picks up existing token from localStorage
login sets user and token on success
login saves tokens to localStorage
login calls api.post with correct endpoint and credentials
login throws and does not update state on failure
loginWithGoogle sets user and token on success
loginWithGoogle saves tokens to localStorage
loginWithGoogle calls api.post with id_token payload
register clears tokens and returns registration data
register sets user to null and initialized to true
logout clears user, token, and localStorage
logout clears state even when API call fails
logout calls the logout endpoint
initializeAuth fetches current user and sets initialized
initializeAuth clears state when /auth/me errors
initializeAuth does nothing when already initialized
syncTokensRefreshed updates token and user from detail
syncTokensRefreshed preserves existing token when not in detail
syncTokensRefreshed preserves existing user when not in detail
syncTokensRefreshed does nothing when called with no argument
syncLoggedOut clears user and token
setHfToken updates user in state with api.put response
setHfToken calls api.put with correct endpoint and payload
setHfToken throws when api.put rejects

✅ Self-Review Checklist

  • Branch based on dev, not main
  • No secrets / API keys added
  • No changes to main or HuggingFace deployment config
  • Follows existing test setup pattern (setup.ts, jsdom, vitest globals)
  • No production code modified

@nancysangani nancysangani requested a review from param20h as a code owner June 22, 2026 09:11
@nancysangani

Copy link
Copy Markdown
Contributor Author

Hi @param20h, please review the PR when you get a chance. Thanks!

@param20h param20h merged commit 7174c3c into param20h:dev Jun 23, 2026
7 checks passed
@github-actions github-actions Bot added gssoc GirlScript Summer of Code 2026 issue/PR gssoc:approved Approved for GSSoC base points (+50 pts) level:intermediate +35 pts mentor:param20h Mentor for this PR type:testing +10 pts labels Jun 23, 2026
@github-actions

Copy link
Copy Markdown

🎉 Congratulations on getting your Pull Request merged! 🎉

Thank you for contributing to PDF-Assistant-RAG as part of GSSoC '26! 🚀

Keep up the great work! ✨

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc:approved Approved for GSSoC base points (+50 pts) gssoc GirlScript Summer of Code 2026 issue/PR level:intermediate +35 pts mentor:param20h Mentor for this PR type:testing +10 pts

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test(frontend): Write unit tests for auth-store (Zustand state)

2 participants