@@ -151,4 +151,24 @@ test('updates admin settings through the CSRF-protected API', async () => {
|
||||
} finally {
|
||||
globalThis.fetch = originalFetch;
|
||||
}
|
||||
});
|
||||
|
||||
test('creates an admin saved view through the CSRF-protected API', async () => {
|
||||
const originalFetch = globalThis.fetch;
|
||||
globalThis.fetch = async (url, options) => {
|
||||
assert.equal(url, '/api/v1/admin/saved-views');
|
||||
assert.equal(options.method, 'POST');
|
||||
assert.equal(options.headers['x-csrf-token'], 'csrf-token');
|
||||
assert.deepEqual(JSON.parse(options.body), { name: 'Recent', filters: { sort: 'recent' } });
|
||||
return { ok: true, async json() { return { data: { id: 'view-1', name: 'Recent', filters: { sort: 'recent' } } }; } };
|
||||
};
|
||||
|
||||
try {
|
||||
const { createAdminSavedView } = await import('../src/services/admin-saved-view-service.js');
|
||||
assert.deepEqual(await createAdminSavedView({ name: 'Recent', filters: { sort: 'recent' } }, 'csrf-token'), {
|
||||
id: 'view-1', name: 'Recent', filters: { sort: 'recent' },
|
||||
});
|
||||
} finally {
|
||||
globalThis.fetch = originalFetch;
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user