Skip to content

Enhancement: add comprehensive tests for session-provider (signIn, signOut, token expiry, storage failure) #599

Description

@henrypeters

Category: Testing - Enhancement
Priority: High
Estimated Time: 3 hours

Description:
components/session-provider.tsx is the most security-critical module in the frontend — it handles authentication, token storage, and the 401 expiry redirect — but it has zero tests. The money utility (lib/money.ts) is the only file with tests. A regression in signIn, the onUnauthorized handler, or the localStorage fallback path would be silent.

Tasks:

  • Add components/__tests__/session-provider.test.tsx
  • Test signIn success: session is persisted and context value updated
  • Test signIn failure: error propagates and session remains null
  • Test signOut: localStorage cleared and session set to null
  • Test 401 handler: signOut is called when onUnauthorized fires
  • Test localStorage unavailable (mock setItem to throw): session still works for the tab
  • Test ready flag: false before localStorage is read, true after
  • Aim for 100% branch coverage on the provider

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    authAuthentication and authorizationtestingTests and test coverage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions