import { expect, it } from 'vitest';
import { createKomgaClient, saveGlobalSetting } from 'komga-sdk';
it('serializes a global setting map as JSON', async () => {
let request: Request | undefined;
const fetchForTest: typeof fetch = async (input, init) => {
request = new Request(input, init);
return new Response(null, { status: 204 });
};
const client = createKomgaClient({ baseUrl: 'https://komga.test', fetch: fetchForTest });
const result = await saveGlobalSetting(
{
body: {
'webui.theme.mode': { value: 'dark', allowUnauthorized: false },
},
},
{ client },
);
expect(result.error).toBeUndefined();
expect(request?.method).toBe('PATCH');
expect(request?.headers.get('content-type')).toContain('application/json');
expect(await request!.text()).toBe(
JSON.stringify({ 'webui.theme.mode': { value: 'dark', allowUnauthorized: false } }),
);
});