Skip to content

Add unit/component tests for the useSessionExpiry hook and SessionExpiryNotification #475

@Baskarayelu

Description

@Baskarayelu

📋 Description

lib/client/useSessionExpiry.ts drives the session-expiry warning rendered by components/SessionExpiryNotification.tsx and wired through components/SessionExpiryProvider.tsx. There are session tests under tests/session, but the client hook's timer/countdown logic and re-authentication trigger are not directly covered.

Why this matters: a wallet-authenticated session that expires mid-flow without a clear warning can drop a user in the middle of a send. The countdown and re-auth prompt are trust-critical.

🎯 Requirements & Context

Functional requirements

  • Add tests/session/use-session-expiry.test.ts (matched by the existing tests/session/** Vitest include).
  • Use fake timers to assert: the warning appears at the threshold, the countdown decrements, expiry triggers the documented action, and re-auth/extend clears the warning.
  • Cover cleanup: timers cleared on unmount (no leaks).

Context & constraints

  • Vitest environment: node; mock timers with vi.useFakeTimers().
  • If the hook reads wall-clock directly, accept an injectable clock for testability (minimal change).

🛠️ Suggested Execution

git checkout -b test/use-session-expiry
  • Write the suite, add injectable clock if needed.
npm run lint
npm run test:coverage
  • Edge cases: session already expired on mount, extend before expiry, rapid mount/unmount, threshold boundary tick.

Example commit message

test(session): cover useSessionExpiry countdown + cleanup

Adds Vitest fake-timer suite for warning threshold, countdown, expiry
action, re-auth reset, and unmount cleanup.

✅ Acceptance Criteria & Guidelines

Requirement Target
Warning/countdown/expiry covered Required
Timer cleanup asserted Required
Hook coverage ≥ 90%
Deterministic (fake timers) Required
Lint clean Required
Timeframe 96 hours from assignment

💬 Community & Support

Join the RemitWise contributor community on Discord: https://discord.gg/CtQuPZFMA

Comment to claim before starting. 🚀

Metadata

Metadata

Assignees

Type

No fields configured for Task.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions