feat(app): profile photo — avatar upload in Mon compte, photo in the sidebar, drawer and top bar
packages/supabase assets module: closed AssetFailure kinds, begin / quarantine upload (upsert off) / confirm / remove, own-row state read with an explicit column list, download under the SELECT policy. App: client transport (magic byte sniff, never SVG, createImageBitmap, canvas 1024 px, JPEG 0.9, 5 MiB cap), AvatarSection (preview, save, 1 s polling up to 30 s, rejection and failure messages per closed code, removal with confirmation, in-flight row resumed at mount), auth store blob URL revoked on change and sign-out, AvatarCircle in UserBadge and the top bar link to Mon compte (D3), FR/EN strings, fake client extended, 27 new tests (app 300).
This commit is contained in:
1 parent
614887470c
commit
926dd7df8c
18 files changed
+1550
-31
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import {
|
||||
createFakeSupabase,
|
||||
fakeAssetRow,
|
||||
fakeSession,
|
||||
flush,
|
||||
type FakeSupabase,
|
||||
@@ -22,6 +23,8 @@ const INITIAL = {
|
||||
roles: [],
|
||||
recovery: false,
|
||||
urlFailure: null,
|
||||
avatar: null,
|
||||
avatarUrl: null,
|
||||
}
|
||||
|
||||
let fake: FakeSupabase
|
||||
@@ -97,6 +100,38 @@ describe('authStore', () => {
|
||||
expect(fake.tables.profiles[0].first_name).toBe('Alice')
|
||||
})
|
||||
|
||||
it('loads the avatar state and downloads the clean photo once', async () => {
|
||||
fake.tables.assets.push(fakeAssetRow())
|
||||
stop = useAuthStore.getState().start()
|
||||
fake.emit('SIGNED_IN', fakeSession())
|
||||
await flush()
|
||||
await flush()
|
||||
const s = useAuthStore.getState()
|
||||
expect(s.avatar?.clean?.id).toBe('asset-1')
|
||||
expect(s.avatarUrl).toMatch(/^blob:/)
|
||||
expect(fake.storage.download).toHaveBeenCalledTimes(1)
|
||||
await useAuthStore.getState().refreshAvatar()
|
||||
expect(fake.storage.download).toHaveBeenCalledTimes(1)
|
||||
fake.tables.assets.push(fakeAssetRow({ id: 'asset-2', object_key: 'profiles/user-1/asset-2/avatar.webp', created_at: '2026-10-13T12:00:00Z' }))
|
||||
fake.tables.assets[0].status = 'deleted'
|
||||
await useAuthStore.getState().refreshAvatar()
|
||||
expect(fake.storage.download).toHaveBeenLastCalledWith('profiles/user-1/asset-2/avatar.webp')
|
||||
})
|
||||
|
||||
it('clearAvatar drops the URL and the clean row; sign-out clears it too', async () => {
|
||||
fake.tables.assets.push(fakeAssetRow())
|
||||
stop = useAuthStore.getState().start()
|
||||
fake.emit('SIGNED_IN', fakeSession())
|
||||
await flush()
|
||||
await flush()
|
||||
useAuthStore.getState().clearAvatar()
|
||||
expect(useAuthStore.getState().avatarUrl).toBeNull()
|
||||
expect(useAuthStore.getState().avatar?.clean).toBeNull()
|
||||
await useAuthStore.getState().refreshAvatar()
|
||||
fake.emit('SIGNED_OUT', null)
|
||||
expect(useAuthStore.getState()).toMatchObject({ avatar: null, avatarUrl: null })
|
||||
})
|
||||
|
||||
it('signOut calls the client and resets the state', async () => {
|
||||
stop = useAuthStore.getState().start()
|
||||
fake.emit('SIGNED_IN', fakeSession())
|
||||
|
||||
Reference in new issue
Block a user