Skip to content

Commit 65d9585

Browse files
committed
test: update required props & improve query enabling conditions
1 parent be79e7e commit 65d9585

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

src/catalogs/hooks.test.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ describe('Catalog Hooks', () => {
174174
mockedGetCatalogDetails.mockResolvedValueOnce(mockCatalog);
175175

176176
const { result } = renderHook(
177-
() => useCatalogDetails({ partnerId: '1', selectedCatalog: '1' }),
177+
() => useCatalogDetails({ partnerId: '1', catalogId: '1' }),
178178
{ wrapper: createWrapper },
179179
);
180180

@@ -202,7 +202,7 @@ describe('Catalog Hooks', () => {
202202
queryClient.setQueryData(['partnerCatalogs', '1', 1, 10], mockCatalogsResponse);
203203

204204
const { result } = renderHook(
205-
() => useCatalogDetails({ partnerId: '1', selectedCatalog: '1' }),
205+
() => useCatalogDetails({ partnerId: '1', catalogId: '1' }),
206206
{ wrapper: createWrapper },
207207
);
208208

@@ -212,23 +212,23 @@ describe('Catalog Hooks', () => {
212212
expect(result.current.isLoadingCatalogDetails).toBe(false);
213213
});
214214

215-
it('should not fetch when partnerId or selectedCatalog is missing', () => {
215+
it('should not fetch when partnerId or catalogId is missing', () => {
216216
const { result: resultNoPartner } = renderHook(
217-
() => useCatalogDetails({ partnerId: '', selectedCatalog: '1' }),
217+
() => useCatalogDetails({ partnerId: '', catalogId: '1' }),
218218
{ wrapper: createWrapper },
219219
);
220220

221221
const { result: resultNoCatalog } = renderHook(
222-
() => useCatalogDetails({ partnerId: '1', selectedCatalog: '' }),
222+
() => useCatalogDetails({ partnerId: '1', catalogId: '' }),
223223
{ wrapper: createWrapper },
224224
);
225225

226226
expect(mockedGetCatalogDetails).not.toHaveBeenCalled();
227227

228-
expect(resultNoPartner.current.catalogDetails).toBeNull();
228+
expect(resultNoPartner.current.catalogDetails).toBeUndefined();
229229
expect(resultNoPartner.current.isLoadingCatalogDetails).toBe(false);
230230

231-
expect(resultNoCatalog.current.catalogDetails).toBeNull();
231+
expect(resultNoCatalog.current.catalogDetails).toBeUndefined();
232232
expect(resultNoCatalog.current.isLoadingCatalogDetails).toBe(false);
233233
});
234234
});

src/catalogs/hooks.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,20 @@ export const usePartnerCatalogs = (
1515

1616
export const useCatalogDetails = ({
1717
partnerId,
18-
selectedCatalog,
19-
}: { partnerId: string; selectedCatalog: string | number; }) => {
18+
catalogId,
19+
}: { partnerId: string; catalogId: string | number; }) => {
2020
const queryClient = useQueryClient();
2121

2222
const allCatalogs = queryClient
2323
.getQueriesData({ queryKey: ['partnerCatalogs', partnerId] })
2424
.flatMap(([, data]) => (data as PaginatedResponse<CorporateCatalog>)?.results ?? []);
2525

26-
const catalogFromCache = allCatalogs.find((c) => c.id === selectedCatalog);
26+
const catalogFromCache = allCatalogs.find((c) => c.id === catalogId);
2727

2828
const { data: catalogDetails, isLoading } = useQuery({
29-
queryKey: ['catalogDetails', partnerId, selectedCatalog],
30-
queryFn: () => getCatalogDetails(partnerId, selectedCatalog),
31-
enabled: !catalogFromCache && !!partnerId && !!selectedCatalog,
29+
queryKey: ['catalogsDetails', partnerId, catalogId],
30+
queryFn: () => getCatalogDetails(partnerId, catalogId),
31+
enabled: !catalogFromCache && !!catalogId && !!partnerId,
3232
});
3333

3434
return {

0 commit comments

Comments
 (0)