Skip to content

Commit 61689e9

Browse files
committed
add all used queries
1 parent 260a174 commit 61689e9

File tree

2 files changed

+89
-4
lines changed

2 files changed

+89
-4
lines changed

src/lib/AnalysisApps/GWAS/Utils/cohortApi.test.tsx

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ import {
1717
useGetCohortDefinitionsQuery,
1818
useGetSourcesQuery,
1919
useGetSourceIdQuery,
20+
useGetCovariatesQuery,
21+
useGetCovariateStatsQuery,
22+
useGetConceptStatsByHareSubsetQuery,
23+
useGetHistogramInfoQuery,
24+
useGetSimpleOverlapInfoQuery,
2025
} from './cohortApi';
2126

2227
const server = setupServer();
@@ -50,6 +55,12 @@ const cohortDefinitionAndStatsData = {
5055
],
5156
};
5257

58+
const covariatesData = { covariates: [{ concept_id: 123, concept_name: 'Test Covariate' }] };
59+
const covariateStatsData = { some_stat: 42 };
60+
const conceptStatsData = { concept_stats: [{ size: 10, concept_name: 'Example' }] };
61+
const histogramData = { bins: [{ start: 0, end: 10, personCount: 5 }] };
62+
const overlapData = { cohort_overlap: { case_control_overlap: 15 } };
63+
5364
describe('cohortApi', () => {
5465
beforeAll(() => {
5566
// Start the interception.
@@ -221,4 +232,76 @@ describe('cohortApi', () => {
221232
data: undefined,
222233
});
223234
});
235+
it('fetches and returns covariates successfully', async () => {
236+
server.use(
237+
http.post(`${GEN3_COHORT_MIDDLEWARE_API}/concept/by-source-id/123/by-type`, () => {
238+
return HttpResponse.json(covariatesData);
239+
})
240+
);
241+
242+
const { result } = renderHook(() => useGetCovariatesQuery('123'));
243+
244+
await waitFor(() => expect(result.current.isSuccess).toBeTruthy());
245+
expect(result.current.data).toEqual(covariatesData);
246+
});
247+
248+
it('fetches and returns covariate stats successfully', async () => {
249+
server.use(
250+
http.post(`${GEN3_COHORT_MIDDLEWARE_API}/concept-stats/by-source-id/123/by-cohort-definition-id/456`, () => {
251+
return HttpResponse.json(covariateStatsData);
252+
})
253+
);
254+
255+
const { result } = renderHook(() =>
256+
useGetCovariateStatsQuery({ sourceId: 123, cohortDefinitionId: '456', selectedCovariateIds: ['789'] })
257+
);
258+
259+
await waitFor(() => expect(result.current.isSuccess).toBeTruthy());
260+
expect(result.current.data).toEqual(covariateStatsData);
261+
});
262+
263+
it('fetches and returns concept stats by HARE subset successfully', async () => {
264+
server.use(
265+
http.post(`${GEN3_COHORT_MIDDLEWARE_API}/concept-stats/by-source-id/123/by-cohort-definition-id/456/breakdown-by-concept-id/2000007027`, () => {
266+
return HttpResponse.json(conceptStatsData);
267+
})
268+
);
269+
270+
const { result } = renderHook(() =>
271+
useGetConceptStatsByHareSubsetQuery({ sourceId: 123, cohortDefinitionId: 456, subsetCovariates: '', outcome: [] })
272+
);
273+
274+
await waitFor(() => expect(result.current.isSuccess).toBeTruthy());
275+
expect(result.current.data).toEqual(conceptStatsData);
276+
});
277+
278+
it('fetches and returns histogram info successfully', async () => {
279+
server.use(
280+
http.post(`${GEN3_COHORT_MIDDLEWARE_API}/histogram/by-source-id/123/by-cohort-definition-id/456/by-histogram-concept-id/789`, () => {
281+
return HttpResponse.json(histogramData);
282+
})
283+
);
284+
285+
const { result } = renderHook(() =>
286+
useGetHistogramInfoQuery({ sourceId: 123, cohortId: 456, selectedCovariates: [], selectedConceptId: 789 })
287+
);
288+
289+
await waitFor(() => expect(result.current.isSuccess).toBeTruthy());
290+
expect(result.current.data).toEqual(histogramData);
291+
});
292+
293+
it('fetches and returns simple overlap info successfully', async () => {
294+
server.use(
295+
http.post(`${GEN3_COHORT_MIDDLEWARE_API}/cohort-stats/check-overlap/by-source-id/123/by-cohort-definition-ids/456/789`, () => {
296+
return HttpResponse.json(overlapData);
297+
})
298+
);
299+
300+
const { result } = renderHook(() =>
301+
useGetSimpleOverlapInfoQuery({ sourceId: 123, cohortAId: 456, cohortBId: 789, selectedCovariates: [] })
302+
);
303+
304+
await waitFor(() => expect(result.current.isSuccess).toBeTruthy());
305+
expect(result.current.data).toEqual(overlapData);
306+
});
224307
});

src/lib/AnalysisApps/GWAS/Utils/cohortApi.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ interface HistogramQueryParams {
7979
sourceId: number;
8080
cohortId: number;
8181
selectedCovariates: Array<Covariates>;
82-
outcome: ConceptOutcome;
82+
outcome?: ConceptOutcome;
8383
selectedConceptId: number;
8484
}
8585

@@ -88,7 +88,7 @@ interface OverlapQueryParams {
8888
cohortAId: number;
8989
cohortBId: number;
9090
selectedCovariates: Array<Covariates>;
91-
outcome: ConceptOutcome;
91+
outcome?: ConceptOutcome;
9292
}
9393

9494
/**
@@ -212,8 +212,8 @@ export const gwasCohortApi = gwasCohortApiTags.injectEndpoints({
212212
sourceId,
213213
cohortId,
214214
selectedCovariates,
215-
outcome,
216215
selectedConceptId,
216+
outcome = {},
217217
}) => {
218218
const variablesPayload = {
219219
variables: [
@@ -241,7 +241,7 @@ export const gwasCohortApi = gwasCohortApiTags.injectEndpoints({
241241
cohortAId,
242242
cohortBId,
243243
selectedCovariates,
244-
outcome,
244+
outcome = {},
245245
}) => {
246246
const variablesPayload = {
247247
variables: [
@@ -266,6 +266,8 @@ export const gwasCohortApi = gwasCohortApiTags.injectEndpoints({
266266
}),
267267
});
268268

269+
// TODO: check if fetchConceptStatsByHareSubsetCC, fetchConceptStatsByHareForCaseControl, and fetchCovariateStats
270+
269271
export const {
270272
useGetCohortDefinitionsQuery,
271273
useGetSourcesQuery,

0 commit comments

Comments
 (0)