Files
TradarrV2/frontend/tests/preferences-api.test.ts
Blomios 50bde816ed feat(accounts): add admin accounts and user preferences
Remove public registration, support administrator-managed accounts, and persist personal preferences.

Refs #2 #5

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-11-20 19:54:06 +01:00

25 lines
1.1 KiB
TypeScript

import { afterEach, expect, it, vi } from 'vitest'
import { preferencesApi } from '../src/api/preferences'
afterEach(() => {
vi.unstubAllGlobals()
localStorage.clear()
})
it('charge et sauvegarde les préférences du compte via GET et PUT /api/me/preferences', async () => {
localStorage.setItem('token', 'user-token')
const initial = { language: 'fr', ranking_mode: 'title' }
const updated = { language: 'en' as const, ranking_mode: 'title_content' as const }
const fetchMock = vi.fn()
.mockResolvedValueOnce(new Response(JSON.stringify({ data: initial }), { status: 200 }))
.mockResolvedValueOnce(new Response(JSON.stringify({ data: updated }), { status: 200 }))
vi.stubGlobal('fetch', fetchMock)
expect(await preferencesApi.get()).toEqual(initial)
expect(await preferencesApi.update(updated)).toEqual(updated)
const headers = { 'Content-Type': 'application/json', Authorization: 'Bearer user-token' }
expect(fetchMock).toHaveBeenNthCalledWith(1, '/api/me/preferences', { headers })
expect(fetchMock).toHaveBeenNthCalledWith(2, '/api/me/preferences', {
method: 'PUT', headers, body: JSON.stringify(updated),
})
})