mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-05-03 21:36:06 +02:00
refactor queryRequest
This commit is contained in:
@@ -4,6 +4,7 @@ import {
|
||||
_entityCacheInternals,
|
||||
fetchWithEntityPolicy,
|
||||
patchAndRefetchActiveQuery,
|
||||
patchUserFromEvent,
|
||||
patchQueryDataWithRecency
|
||||
} from '../entityCache';
|
||||
import { queryClient } from '../client';
|
||||
@@ -130,4 +131,54 @@ describe('entity query cache helpers', () => {
|
||||
false
|
||||
);
|
||||
});
|
||||
|
||||
test('internal completeness guard requires params + entity identifier', () => {
|
||||
expect(_entityCacheInternals.hasCompleteEntityData(undefined)).toBe(
|
||||
false
|
||||
);
|
||||
expect(_entityCacheInternals.hasCompleteEntityData({})).toBe(false);
|
||||
expect(
|
||||
_entityCacheInternals.hasCompleteEntityData({
|
||||
params: {}
|
||||
})
|
||||
).toBe(false);
|
||||
expect(
|
||||
_entityCacheInternals.hasCompleteEntityData({
|
||||
params: { userId: 'usr_1' }
|
||||
})
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
test('patchUserFromEvent skips placeholder cache entries', () => {
|
||||
const queryKey = ['user', 'usr_1'];
|
||||
queryClient.setQueryData(queryKey, {
|
||||
params: {}
|
||||
});
|
||||
|
||||
patchUserFromEvent({
|
||||
id: 'usr_1',
|
||||
displayName: 'Alice'
|
||||
});
|
||||
|
||||
expect(queryClient.getQueryData(queryKey)).toEqual({
|
||||
params: {}
|
||||
});
|
||||
});
|
||||
|
||||
test('patchUserFromEvent patches when query has complete data', () => {
|
||||
const queryKey = ['user', 'usr_1'];
|
||||
queryClient.setQueryData(queryKey, {
|
||||
params: { userId: 'usr_1' },
|
||||
ref: { id: 'usr_1', displayName: 'Old' },
|
||||
json: { id: 'usr_1', displayName: 'Old' }
|
||||
});
|
||||
|
||||
patchUserFromEvent({
|
||||
id: 'usr_1',
|
||||
displayName: 'New'
|
||||
});
|
||||
|
||||
const data = queryClient.getQueryData(queryKey);
|
||||
expect(data.ref.displayName).toBe('New');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -50,13 +50,6 @@ describe('query policy configuration', () => {
|
||||
refetchOnWindowFocus: false
|
||||
});
|
||||
|
||||
expect(entityQueryPolicies.instance).toMatchObject({
|
||||
staleTime: 0,
|
||||
gcTime: 10000,
|
||||
retry: 0,
|
||||
refetchOnWindowFocus: false
|
||||
});
|
||||
|
||||
expect(entityQueryPolicies.friendList).toMatchObject({
|
||||
staleTime: 20000,
|
||||
gcTime: 90000,
|
||||
@@ -104,9 +97,6 @@ describe('query policy configuration', () => {
|
||||
expect(getEntityQueryPolicy('worldCollection')).toBe(
|
||||
entityQueryPolicies.worldCollection
|
||||
);
|
||||
expect(getEntityQueryPolicy('instance')).toBe(
|
||||
entityQueryPolicies.instance
|
||||
);
|
||||
expect(getEntityQueryPolicy('friendList')).toBe(
|
||||
entityQueryPolicies.friendList
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user