Files
VRCX/src/api/__tests__/groupQuerySync.test.js
2026-03-13 20:04:30 +09:00

60 lines
1.5 KiB
JavaScript

import { beforeEach, describe, expect, test, vi } from 'vitest';
const mockRequest = vi.fn();
const mockInvalidateQueries = vi.fn().mockResolvedValue();
const mockApplyGroup = vi.fn((json) => json);
vi.mock('../../service/request', () => ({
request: (...args) => mockRequest(...args)
}));
vi.mock('../../stores', () => ({
useGroupStore: () => ({
applyGroup: (...args) => mockApplyGroup(...args)
}),
useUserStore: () => ({
currentUser: { id: 'usr_me' }
})
}));
vi.mock('../../queries', () => ({
queryClient: {
invalidateQueries: (...args) => mockInvalidateQueries(...args)
},
entityQueryPolicies: {
user: {},
avatar: {},
world: {},
worldCollection: {}
}
}));
import groupRequest from '../group';
describe('group query sync', () => {
beforeEach(() => {
vi.clearAllMocks();
});
test('group mutations invalidate scoped active group queries', async () => {
mockRequest.mockResolvedValue({ ok: true });
await groupRequest.setGroupRepresentation('grp_1', {
isRepresenting: true
});
await groupRequest.deleteGroupPost({
groupId: 'grp_1',
postId: 'post_1'
});
await groupRequest.setGroupMemberProps('usr_me', 'grp_1', {
visibility: 'visible'
});
expect(mockInvalidateQueries).toHaveBeenCalledTimes(3);
expect(mockInvalidateQueries).toHaveBeenCalledWith({
queryKey: ['group', 'grp_1'],
refetchType: 'active'
});
});
});