test(ui): add coverage for use-api-session.ts (#7903)#7955
Conversation
use-api-session.ts (the wallet-signature challenge->sign->verify session hook) had zero coverage. This suite is plain-node (no DOM/renderHook per apps/ui/vitest.config.ts), so extract the hook's two pure pieces as named exports and cover them directly: the address-scoped, expiry-checked sessionStorage read/write helpers, and performWalletSignIn -- the challenge->sign->verify orchestration with its deps (apiFetch/signMessage/now) injectable for the test. The hook's signIn now delegates to performWalletSignIn; behavior is unchanged. Covers: the full challenge->sign->verify flow and session shape, ApiError propagation, and readStoredSession's round-trip / wrong-address / expired / malformed-JSON / storage-throws / SSR-no-window paths.
|
Superagent didn't find any vulnerabilities or security issues in this PR. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7955 +/- ##
=======================================
Coverage 97.58% 97.58%
=======================================
Files 204 204
Lines 26365 26365
Branches 10452 10452
=======================================
Hits 25729 25729
Misses 150 150
Partials 486 486 🚀 New features to boost your workflow:
|
|
Warning ⏸️ LoopOver review result - manual review recommendedReview updated: 2026-07-24 16:21:17 UTC
Review summary Nits — 4 non-blocking
Decision drivers
Context & advisory signals — never blocks the verdict
Review context
Contributor next steps
Signal definitions
🧪 Chat with LoopOverAsk LoopOver a question about this PR directly in a comment — grounded only in the same cached, public-safe facts shown above, never a new claim.
Full command reference: https://loopover.ai/docs/loopover-commands 🧪 Experimental — new and may change. 🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed 💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →. Checked by LoopOver, a quiet PR intelligence layer for OSS maintainers.
|
Closes #7903
What
apps/ui/src/hooks/use-api-session.ts— the wallet-signaturechallenge → sign → verifysession hook (sessionStorage-persisted, address-scoped, expiry-checked) — had zero test coverage. This adds it.How
This suite is plain-node (no DOM, no
renderHook— seeapps/ui/vitest.config.ts, and no hook test in the repo renders), so I cover the hook's real logic through its two extracted, exported pure pieces — matching the repo's "test the extracted pure function" convention (e.g.use-move-stake-flow):readStoredSession/writeStoredSession— the address-scoped, expiry-checked sessionStorage helpers (addedexport).performWalletSignIn(wallet, deps)— thechallenge → sign → verify → session-shapeorchestration, split out ofsignInwithapiFetch/signMessage/nowdependency-injected so it's testable without a DOM. The hook'ssignInnow delegates to it; behavior is unchanged.Tests —
apps/ui/src/hooks/use-api-session.test.ts(10 cases)performWalletSignIn: the full challenge→sign→verify flow (asserts the POST paths/bodies, the signer call, and the shaped session incl.expiresAtMs = now + expires_in*1000);ApiErrorpropagation.readStoredSession/writeStoredSession: round-trip, wrong-address rejection, expired rejection, empty, malformed-JSON (never throws), storage-throws (never throws), clear-on-null, and the SSR no-windowno-op.Scoped to
apps/ui/src/hooks/— no visual/component change, so it follows the normal (non-screenshot-gated) review path per the frontend contribution rules.npx vitest run src/hooks/use-api-session.test.ts— 10 passedCloses #7903)