initial commit
This commit is contained in:
commit
6ffc0d2c99
54 changed files with 11900 additions and 0 deletions
60
frontend/src/api.test.ts
Normal file
60
frontend/src/api.test.ts
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { api, authStorage } from './api'
|
||||
|
||||
describe('API client', () => {
|
||||
beforeEach(() => {
|
||||
sessionStorage.clear()
|
||||
})
|
||||
|
||||
it('sends the persisted bearer token on protected requests', async () => {
|
||||
authStorage.save({
|
||||
token: 'signed-jwt',
|
||||
user: { id: 1, email: 'admin@example.com', role: 'admin' },
|
||||
})
|
||||
const fetchMock = vi.fn().mockResolvedValue(new Response('[]', { status: 200 }))
|
||||
vi.stubGlobal('fetch', fetchMock)
|
||||
|
||||
await api.jobs.list()
|
||||
|
||||
expect(fetchMock).toHaveBeenCalledWith(
|
||||
'/api/jobs',
|
||||
expect.objectContaining({
|
||||
headers: expect.objectContaining({ Authorization: 'Bearer signed-jwt' }),
|
||||
}),
|
||||
)
|
||||
})
|
||||
|
||||
it('uses the backend participant multipart field names', async () => {
|
||||
authStorage.save({
|
||||
token: 'signed-jwt',
|
||||
user: { id: 1, email: 'admin@example.com', role: 'admin' },
|
||||
})
|
||||
const fetchMock = vi.fn().mockResolvedValue(
|
||||
new Response(
|
||||
JSON.stringify({
|
||||
id: 4,
|
||||
firstName: 'A',
|
||||
lastName: 'B',
|
||||
email: 'a@example.com',
|
||||
contactInfo: 'Brussels',
|
||||
traits: [],
|
||||
createdAt: '2026-09-01T00:00:00Z',
|
||||
}),
|
||||
{ status: 201, headers: { 'Content-Type': 'application/json' } },
|
||||
),
|
||||
)
|
||||
vi.stubGlobal('fetch', fetchMock)
|
||||
|
||||
await api.participants.create({
|
||||
firstName: 'A',
|
||||
lastName: 'B',
|
||||
birthday: '1990-01-02',
|
||||
email: 'a@example.com',
|
||||
contactInfo: 'Brussels',
|
||||
})
|
||||
|
||||
const options = fetchMock.mock.calls[0][1] as RequestInit
|
||||
const form = options.body as FormData
|
||||
expect([...form.keys()]).toEqual(['firstName', 'lastName', 'birthday', 'email', 'contactInfo'])
|
||||
})
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue