@@ -17,6 +17,11 @@ import {
17
17
useGetCohortDefinitionsQuery ,
18
18
useGetSourcesQuery ,
19
19
useGetSourceIdQuery ,
20
+ useGetCovariatesQuery ,
21
+ useGetCovariateStatsQuery ,
22
+ useGetConceptStatsByHareSubsetQuery ,
23
+ useGetHistogramInfoQuery ,
24
+ useGetSimpleOverlapInfoQuery ,
20
25
} from './cohortApi' ;
21
26
22
27
const server = setupServer ( ) ;
@@ -50,6 +55,12 @@ const cohortDefinitionAndStatsData = {
50
55
] ,
51
56
} ;
52
57
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
+
53
64
describe ( 'cohortApi' , ( ) => {
54
65
beforeAll ( ( ) => {
55
66
// Start the interception.
@@ -221,4 +232,76 @@ describe('cohortApi', () => {
221
232
data : undefined ,
222
233
} ) ;
223
234
} ) ;
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
+ } ) ;
224
307
} ) ;
0 commit comments