Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions src/hooks/__tests__/queryKeyIntegration.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { renderHook } from '@testing-library/react';
import { beforeEach, describe, expect, it } from 'vitest';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import React from 'react';

import { queryKeys } from '@/lib/queryKeys';
import { useCreatorList, useCreatorDetail } from '../useCreators';
import { useWalletHoldings, useWalletActivity } from '../useWallet';

describe('queryKeyIntegration', () => {
let queryClient: QueryClient;

beforeEach(() => {
queryClient = new QueryClient({
defaultOptions: { queries: { retry: false } },
});
});

const wrapper = ({ children }: { children: React.ReactNode }) => (
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
);

it('useCreatorList uses the correct query key constant', () => {
const params = { page: 1 };
renderHook(() => useCreatorList(params), { wrapper });

const cache = queryClient.getQueryCache().getAll();
expect(cache).toHaveLength(1);
expect(cache[0].queryKey).toEqual(queryKeys.creators.list(params));
});

it('useCreatorDetail uses the correct query key constant', () => {
renderHook(() => useCreatorDetail('creator-1'), { wrapper });

const cache = queryClient.getQueryCache().getAll();
expect(cache).toHaveLength(1);
expect(cache[0].queryKey).toEqual(queryKeys.creators.detail('creator-1'));
});

it('useWalletHoldings uses the correct query key constant', () => {
renderHook(() => useWalletHoldings('0x123'), { wrapper });

const cache = queryClient.getQueryCache().getAll();
expect(cache).toHaveLength(1);
expect(cache[0].queryKey).toEqual(queryKeys.wallet.holdings('0x123'));
});

it('useWalletActivity uses the correct query key constant', () => {
renderHook(() => useWalletActivity('0x123'), { wrapper });

const cache = queryClient.getQueryCache().getAll();
expect(cache).toHaveLength(1);
expect(cache[0].queryKey).toEqual(queryKeys.wallet.activity('0x123'));
});
});
18 changes: 18 additions & 0 deletions src/hooks/useCreators.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { useQuery } from '@tanstack/react-query';
import { queryKeys } from '@/lib/queryKeys';
import type { GetCoursesParams } from '@/services/course.service';

export function useCreatorList(params?: GetCoursesParams) {
return useQuery({
queryKey: queryKeys.creators.list(params),
queryFn: async () => [],
});
}

export function useCreatorDetail(id: string) {
return useQuery({
queryKey: queryKeys.creators.detail(id),
queryFn: async () => null,
enabled: !!id,
});
}
18 changes: 18 additions & 0 deletions src/hooks/useWallet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { useQuery } from '@tanstack/react-query';
import { queryKeys } from '@/lib/queryKeys';

export function useWalletHoldings(address: string) {
return useQuery({
queryKey: queryKeys.wallet.holdings(address),
queryFn: async () => [],
enabled: !!address,
});
}

export function useWalletActivity(address: string) {
return useQuery({
queryKey: queryKeys.wallet.activity(address),
queryFn: async () => [],
enabled: !!address,
});
}
Loading