@@ -116,4 +116,24 @@ test('updates selected admin inventory tags through the bulk API', async () => {
|
||||
} finally {
|
||||
globalThis.fetch = originalFetch;
|
||||
}
|
||||
});
|
||||
|
||||
test('updates admin settings through the CSRF-protected API', async () => {
|
||||
const originalFetch = globalThis.fetch;
|
||||
globalThis.fetch = async (url, options) => {
|
||||
assert.equal(url, '/api/v1/admin/settings');
|
||||
assert.equal(options.method, 'PATCH');
|
||||
assert.equal(options.headers['x-csrf-token'], 'csrf-token');
|
||||
assert.deepEqual(JSON.parse(options.body), { pricing: { defaultStrategy: 'median' } });
|
||||
return { ok: true, async json() { return { data: { pricing: { defaultStrategy: 'median' } } }; } };
|
||||
};
|
||||
|
||||
try {
|
||||
const { updateAdminSettings } = await import('../src/services/admin-settings-service.js');
|
||||
assert.deepEqual(await updateAdminSettings({ pricing: { defaultStrategy: 'median' } }, 'csrf-token'), {
|
||||
pricing: { defaultStrategy: 'median' },
|
||||
});
|
||||
} finally {
|
||||
globalThis.fetch = originalFetch;
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user