mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-04-20 07:13:51 +02:00
refactor queryRequest
This commit is contained in:
@@ -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 mockHandleFavoriteAdd = vi.fn();
|
||||
const mockHandleFavoriteDelete = vi.fn();
|
||||
@@ -24,24 +23,8 @@ vi.mock('../../stores', () => ({
|
||||
}));
|
||||
|
||||
vi.mock('../../queries', () => ({
|
||||
entityQueryPolicies: {
|
||||
favoriteCollection: {
|
||||
staleTime: 60000,
|
||||
gcTime: 300000,
|
||||
retry: 1,
|
||||
refetchOnWindowFocus: false
|
||||
}
|
||||
},
|
||||
fetchWithEntityPolicy: (...args) => mockFetchWithEntityPolicy(...args),
|
||||
queryClient: {
|
||||
invalidateQueries: (...args) => mockInvalidateQueries(...args)
|
||||
},
|
||||
queryKeys: {
|
||||
favoriteLimits: () => ['favorite', 'limits'],
|
||||
favorites: (params) => ['favorite', 'items', params],
|
||||
favoriteGroups: (params) => ['favorite', 'groups', params],
|
||||
favoriteWorlds: (params) => ['favorite', 'worlds', params],
|
||||
favoriteAvatars: (params) => ['favorite', 'avatars', params]
|
||||
}
|
||||
}));
|
||||
|
||||
@@ -52,21 +35,6 @@ describe('favorite query sync', () => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
test('cached favorite reads go through fetchWithEntityPolicy', async () => {
|
||||
mockFetchWithEntityPolicy.mockResolvedValue({
|
||||
data: { json: [], params: { n: 300, offset: 0 } },
|
||||
cache: true
|
||||
});
|
||||
|
||||
const args = await favoriteRequest.getCachedFavorites({
|
||||
n: 300,
|
||||
offset: 0
|
||||
});
|
||||
|
||||
expect(mockFetchWithEntityPolicy).toHaveBeenCalled();
|
||||
expect(args.cache).toBe(true);
|
||||
});
|
||||
|
||||
test('favorite mutations invalidate active favorite queries', async () => {
|
||||
mockRequest.mockResolvedValue({ ok: true });
|
||||
|
||||
|
||||
Reference in New Issue
Block a user