mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-04-19 23:03: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 mockRemoveQueries = vi.fn();
|
||||
|
||||
@@ -16,27 +15,6 @@ vi.mock('../../stores', () => ({
|
||||
}));
|
||||
|
||||
vi.mock('../../queries', () => ({
|
||||
entityQueryPolicies: {
|
||||
galleryCollection: {
|
||||
staleTime: 60000,
|
||||
gcTime: 300000,
|
||||
retry: 1,
|
||||
refetchOnWindowFocus: false
|
||||
},
|
||||
inventoryCollection: {
|
||||
staleTime: 20000,
|
||||
gcTime: 120000,
|
||||
retry: 1,
|
||||
refetchOnWindowFocus: false
|
||||
},
|
||||
fileObject: {
|
||||
staleTime: 60000,
|
||||
gcTime: 300000,
|
||||
retry: 1,
|
||||
refetchOnWindowFocus: false
|
||||
}
|
||||
},
|
||||
fetchWithEntityPolicy: (...args) => mockFetchWithEntityPolicy(...args),
|
||||
queryClient: {
|
||||
invalidateQueries: (...args) => mockInvalidateQueries(...args),
|
||||
removeQueries: (...args) => mockRemoveQueries(...args)
|
||||
@@ -51,7 +29,6 @@ vi.mock('../../queries', () => ({
|
||||
}
|
||||
}));
|
||||
|
||||
import inventoryRequest from '../inventory';
|
||||
import miscRequest from '../misc';
|
||||
import vrcPlusIconRequest from '../vrcPlusIcon';
|
||||
import vrcPlusImageRequest from '../vrcPlusImage';
|
||||
@@ -61,25 +38,6 @@ describe('media and inventory query sync', () => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
test('cached media/inventory reads go through fetchWithEntityPolicy', async () => {
|
||||
mockFetchWithEntityPolicy.mockResolvedValue({
|
||||
data: { json: [], params: {} },
|
||||
cache: true
|
||||
});
|
||||
|
||||
const a = await vrcPlusIconRequest.getCachedFileList({ tag: 'icon', n: 100 });
|
||||
const b = await vrcPlusImageRequest.getCachedPrints({ n: 100 });
|
||||
const c = await inventoryRequest.getCachedInventoryItems({
|
||||
n: 100,
|
||||
offset: 0,
|
||||
order: 'newest'
|
||||
});
|
||||
const d = await miscRequest.getCachedFile({ fileId: 'file_1' });
|
||||
|
||||
expect(mockFetchWithEntityPolicy).toHaveBeenCalledTimes(4);
|
||||
expect(a.cache && b.cache && c.cache && d.cache).toBe(true);
|
||||
});
|
||||
|
||||
test('media mutations invalidate gallery queries and file delete removes file query', async () => {
|
||||
mockRequest.mockResolvedValue({ ok: true });
|
||||
|
||||
|
||||
Reference in New Issue
Block a user