import { describe, expect, it, vi } from 'vitest'; import { listFiles, uploadFileResource } from './files'; describe('files API', () => { it('lists file resources by kind', async () => { const fetchMock = vi.mocked(fetch); fetchMock.mockResolvedValueOnce({ ok: true, status: 200, headers: new Headers({ 'content-type': 'application/json' }), json: () => Promise.resolve({ data: { items: [] } }), text: () => Promise.resolve(''), } as Response); await expect(listFiles('TEMPLATE_ASSET')).resolves.toEqual([]); expect(fetchMock).toHaveBeenCalledWith('/api/files?kind=TEMPLATE_ASSET', expect.objectContaining({ credentials: 'include', })); }); it('uploads a generic file resource', async () => { const fetchMock = vi.mocked(fetch); fetchMock.mockResolvedValueOnce({ ok: true, status: 200, headers: new Headers({ 'content-type': 'application/json' }), json: () => Promise.resolve({ data: { file: { id: 'file_1', filename: 'a.png', mimeType: 'image/png', size: 10, url: '/api/files/file_1/content', createdAt: '2026-05-02T00:00:00.000Z' } } }), text: () => Promise.resolve(''), } as Response); await expect(uploadFileResource('data:image/png;base64,AA==', { filename: 'a.png' })).resolves.toMatchObject({ id: 'file_1' }); expect(fetchMock).toHaveBeenCalledWith('/api/files', expect.objectContaining({ method: 'POST', credentials: 'include', })); }); });