Files
bchanot aa1985eead test(app): identity step — auth store, locale sync, login/signup, guards, shell, dashboard, account
- tests/helpers/fakeSupabase: in-memory auth events + profiles/profile_roles builder
- validation schemas and safeNextPath; classifyAuthError mapping (packages/supabase)
- LoginRoute (unavailable, validation, next path, phrased failure, OAuth buttons, show password)
- SignupRoute (policy, mismatch, metadata + redirect, user exists)
- RequireAuth / RedirectIfSignedIn, AppLayout (nav, active, drawer, sign out), Dashboard, Account forms
2026-10-11 23:33:25 +02:00

26 lines
1.4 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import type { AuthError } from '@supabase/supabase-js'
import { classifyAuthError } from '../src/auth'
function err(patch: Partial<AuthError> & { code?: string }): AuthError {
return { name: 'AuthApiError', message: 'm', ...patch } as AuthError
}
describe('classifyAuthError', () => {
it('maps GoTrue codes to the closed kinds the UI phrases', () => {
expect(classifyAuthError(err({ code: 'invalid_credentials', status: 400 }))).toBe('invalid_credentials')
expect(classifyAuthError(err({ code: 'email_not_confirmed', status: 400 }))).toBe('email_not_confirmed')
expect(classifyAuthError(err({ code: 'user_already_exists', status: 422 }))).toBe('user_exists')
expect(classifyAuthError(err({ code: 'weak_password', status: 422 }))).toBe('weak_password')
expect(classifyAuthError(err({ code: 'otp_expired', status: 403 }))).toBe('link_expired')
expect(classifyAuthError(err({ code: 'bad_code_verifier', status: 400 }))).toBe('link_expired')
})
it('falls back on the HTTP status, then network, then unknown', () => {
expect(classifyAuthError(err({ status: 429 }))).toBe('rate_limited')
expect(classifyAuthError(err({ status: 400, message: 'Invalid login credentials' }))).toBe('invalid_credentials')
expect(classifyAuthError(err({ status: 0 }))).toBe('network')
expect(classifyAuthError(err({ status: 500, code: 'unexpected_failure' }))).toBe('unknown')
})
})