refactor queryRequest

This commit is contained in:
pa
2026-03-09 21:28:45 +09:00
parent c1a35223d4
commit 58b9bdc1c5
60 changed files with 1134 additions and 883 deletions

View File

@@ -1,7 +1,6 @@
import { beforeEach, describe, expect, test, vi } from 'vitest';
const mockRequest = vi.fn();
const mockFetchWithEntityPolicy = vi.fn();
const mockInvalidateQueries = vi.fn().mockResolvedValue();
const mockApplyGroup = vi.fn((json) => json);
@@ -19,32 +18,8 @@ vi.mock('../../stores', () => ({
}));
vi.mock('../../queries', () => ({
entityQueryPolicies: {
group: {
staleTime: 60000,
gcTime: 300000,
retry: 1,
refetchOnWindowFocus: false
},
groupCollection: {
staleTime: 60000,
gcTime: 300000,
retry: 1,
refetchOnWindowFocus: false
}
},
fetchWithEntityPolicy: (...args) => mockFetchWithEntityPolicy(...args),
queryClient: {
invalidateQueries: (...args) => mockInvalidateQueries(...args)
},
queryKeys: {
group: (groupId, includeRoles) => ['group', groupId, Boolean(includeRoles)],
groupPosts: (params) => ['group', params.groupId, 'posts', params],
groupMember: (params) => ['group', params.groupId, 'member', params.userId],
groupMembers: (params) => ['group', params.groupId, 'members', params],
groupGallery: (params) => ['group', params.groupId, 'gallery', params.galleryId, params],
groupCalendar: (groupId) => ['group', groupId, 'calendar'],
groupCalendarEvent: (params) => ['group', params.groupId, 'calendarEvent', params.eventId]
}
}));
@@ -55,29 +30,6 @@ describe('group query sync', () => {
vi.clearAllMocks();
});
test('cached group resources use fetchWithEntityPolicy', async () => {
mockFetchWithEntityPolicy.mockResolvedValue({
data: { json: [], params: { groupId: 'grp_1', n: 100, offset: 0 } },
cache: true
});
const a = await groupRequest.getCachedGroupMembers({
groupId: 'grp_1',
n: 100,
offset: 0,
sort: 'joinedAt:desc'
});
const b = await groupRequest.getCachedGroupGallery({
groupId: 'grp_1',
galleryId: 'gal_1',
n: 100,
offset: 0
});
expect(mockFetchWithEntityPolicy).toHaveBeenCalledTimes(2);
expect(a.cache && b.cache).toBe(true);
});
test('group mutations invalidate scoped active group queries', async () => {
mockRequest.mockResolvedValue({ ok: true });