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,67 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import {
|
||||
createFakeSupabase,
|
||||
fakeProfile,
|
||||
fakeSession,
|
||||
flush,
|
||||
type FakeSupabase,
|
||||
} from '../helpers/fakeSupabase'
|
||||
|
||||
const mocks = vi.hoisted(() => ({ fake: null as unknown }))
|
||||
vi.mock('@/lib/supabase', () => ({
|
||||
getSupabaseClient: () => (mocks.fake as FakeSupabase | null)?.client ?? null,
|
||||
isSupabaseConfigured: () => mocks.fake !== null,
|
||||
}))
|
||||
|
||||
import { useAuthStore } from '@/state/authStore'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
import { startLocaleSync } from '@/services/localeSync'
|
||||
|
||||
let fake: FakeSupabase
|
||||
let stops: Array<() => void> = []
|
||||
|
||||
beforeEach(() => {
|
||||
localStorage.clear()
|
||||
useLocaleStore.setState({ locale: 'fr' })
|
||||
useAuthStore.setState({
|
||||
status: 'loading',
|
||||
session: null,
|
||||
user: null,
|
||||
profile: null,
|
||||
roles: [],
|
||||
recovery: false,
|
||||
urlFailure: null,
|
||||
})
|
||||
fake = createFakeSupabase({
|
||||
profiles: [fakeProfile({ locale: 'en' })],
|
||||
profile_roles: [],
|
||||
})
|
||||
mocks.fake = fake
|
||||
stops = [useAuthStore.getState().start(), startLocaleSync()]
|
||||
})
|
||||
afterEach(() => stops.forEach((s) => s()))
|
||||
|
||||
describe('locale sync', () => {
|
||||
it('applies the account locale once when the profile loads', async () => {
|
||||
fake.emit('SIGNED_IN', fakeSession())
|
||||
await flush()
|
||||
expect(useLocaleStore.getState().locale).toBe('en')
|
||||
expect(localStorage.getItem('osteo:locale')).toBe('en')
|
||||
})
|
||||
|
||||
it('saves a language switch to profiles.locale while signed in', async () => {
|
||||
fake.emit('SIGNED_IN', fakeSession())
|
||||
await flush()
|
||||
useLocaleStore.getState().setLocale('fr')
|
||||
await flush()
|
||||
expect(fake.tables.profiles[0].locale).toBe('fr')
|
||||
expect(useAuthStore.getState().profile?.locale).toBe('fr')
|
||||
})
|
||||
|
||||
it('leaves the profile alone when signed out', async () => {
|
||||
fake.emit('INITIAL_SESSION', null)
|
||||
useLocaleStore.getState().setLocale('fr')
|
||||
await flush()
|
||||
expect(fake.tables.profiles[0].locale).toBe('en')
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user