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
This commit is contained in:
1 parent
c517ea267b
commit
aa1985eead
11 files changed
+993
No files matched your search
@@ -0,0 +1,115 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import {
|
||||
fieldErrors,
|
||||
loginSchema,
|
||||
newPasswordSchema,
|
||||
passwordSchema,
|
||||
signupSchema,
|
||||
} from '@/auth/validation'
|
||||
import { safeNextPath } from '@/auth/redirects'
|
||||
import {
|
||||
personalPatch,
|
||||
personalSchema,
|
||||
professionalSchema,
|
||||
translateFieldError,
|
||||
} from '@/account/validation'
|
||||
|
||||
describe('auth validation', () => {
|
||||
it('password mirrors the server policy: 12 chars, lower, upper, digit', () => {
|
||||
expect(passwordSchema.safeParse('Short1aA').success).toBe(false)
|
||||
expect(passwordSchema.safeParse('alllowercase123').success).toBe(false)
|
||||
expect(passwordSchema.safeParse('NoDigitsHereAtAll').success).toBe(false)
|
||||
expect(passwordSchema.safeParse('CorrectHorse12').success).toBe(true)
|
||||
})
|
||||
|
||||
it('reports one i18n key per field, first issue wins', () => {
|
||||
const r = loginSchema.safeParse({ email: 'nope', password: '' })
|
||||
expect(r.success).toBe(false)
|
||||
if (!r.success) {
|
||||
expect(fieldErrors(r.error)).toEqual({
|
||||
email: 'auth.error.email_invalid',
|
||||
password: 'auth.error.password_required',
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
it('signup flags a confirmation mismatch on the confirm field', () => {
|
||||
const r = signupSchema.safeParse({
|
||||
displayName: 'A',
|
||||
email: 'a@b.co',
|
||||
password: 'CorrectHorse12',
|
||||
passwordConfirm: 'CorrectHorse13',
|
||||
})
|
||||
expect(r.success).toBe(false)
|
||||
if (!r.success) {
|
||||
expect(fieldErrors(r.error).passwordConfirm).toBe('auth.error.password_mismatch')
|
||||
}
|
||||
expect(
|
||||
newPasswordSchema.safeParse({ password: 'CorrectHorse12', passwordConfirm: 'x' })
|
||||
.success,
|
||||
).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('safeNextPath', () => {
|
||||
it('keeps same-origin paths and refuses anything else', () => {
|
||||
expect(safeNextPath('/app/account')).toBe('/app/account')
|
||||
expect(safeNextPath(null)).toBe('/app')
|
||||
expect(safeNextPath('https://evil.test/')).toBe('/app')
|
||||
expect(safeNextPath('//evil.test')).toBe('/app')
|
||||
expect(safeNextPath('app')).toBe('/app')
|
||||
})
|
||||
})
|
||||
|
||||
describe('account validation', () => {
|
||||
it('turns empty optional fields into null and keeps display_name', () => {
|
||||
const r = personalSchema.safeParse({
|
||||
display_name: ' Alice ',
|
||||
first_name: '',
|
||||
last_name: 'Local',
|
||||
phone: '',
|
||||
})
|
||||
expect(r.success).toBe(true)
|
||||
if (r.success) {
|
||||
expect(personalPatch(r.data)).toEqual({
|
||||
display_name: 'Alice',
|
||||
first_name: null,
|
||||
last_name: 'Local',
|
||||
phone: null,
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
it('checks phone E.164 and SIRET 14 digits (spaces tolerated)', () => {
|
||||
const bad = personalSchema.safeParse({
|
||||
display_name: 'A',
|
||||
first_name: '',
|
||||
last_name: '',
|
||||
phone: '06 12',
|
||||
})
|
||||
expect(bad.success).toBe(false)
|
||||
const siretOk = professionalSchema.safeParse({
|
||||
professional_title: '',
|
||||
practice_name: '',
|
||||
siret: '123 456 789 01234',
|
||||
})
|
||||
expect(siretOk.success).toBe(true)
|
||||
if (siretOk.success) expect(siretOk.data.siret).toBe('12345678901234')
|
||||
const siretBad = professionalSchema.safeParse({
|
||||
professional_title: '',
|
||||
practice_name: '',
|
||||
siret: '1234',
|
||||
})
|
||||
expect(siretBad.success).toBe(false)
|
||||
if (!siretBad.success) {
|
||||
expect(fieldErrors(siretBad.error).siret).toBe('account.error.siret_format')
|
||||
}
|
||||
})
|
||||
|
||||
it('translates a key|value message with its placeholder', () => {
|
||||
const t = (k: string) => (k === 'account.error.too_long' ? 'Max {max}' : k)
|
||||
expect(translateFieldError(t, 'account.error.too_long|80')).toBe('Max 80')
|
||||
expect(translateFieldError(t, 'account.error.required')).toBe('account.error.required')
|
||||
expect(translateFieldError(t, undefined)).toBeUndefined()
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user