Files
q-blog/tests/utils/wikiSettingsCache.test.ts

38 lines
1.3 KiB
TypeScript

import { describe, it, expect } from 'vitest';
import { server } from '../msw/server';
import { http, HttpResponse } from 'msw';
import { getCachedBlogSettings } from '@/utils/wikiSettingsCache';
describe('wikiSettingsCache', () => {
it('returns owner and settings from QDN', async () => {
server.use(
http.get('/arbitrary/resources', ({ request }) => {
const url = new URL(request.url);
if (
url.searchParams.get('service') === 'BLOG' &&
url.searchParams.get('identifier') === 'q-blog-myblog'
) {
return HttpResponse.json([{ name: 'alice', identifier: 'q-blog-myblog' }]);
}
return HttpResponse.json([]);
}),
http.get('/arbitrary/BLOG/:name/:id', ({ params }) => {
const { name, id } = params as any;
if (name === 'alice' && id === 'q-blog-myblog') {
return HttpResponse.json({
wikiEnabled: true,
editorWhitelist: ['bob'],
editorBlacklist: [],
});
}
return HttpResponse.json({}, { status: 404 });
}),
);
const { ownerName, settings } = await getCachedBlogSettings('q-blog-myblog');
expect(ownerName).toBe('alice');
expect(settings.wikiEnabled).toBe(true);
expect(settings.editorWhitelist).toContain('bob');
});
});