@@ -11,7 +11,8 @@ function parseRequestPayload(mockApiCall?: RequestInit) {
1111 return JSON . parse ( mockApiCall . body as string ) ;
1212}
1313
14- describe ( 'useStacSearch' , ( ) => {
14+ describe ( 'useStacSearch — API supports POST' , ( ) => {
15+ fetch . mockResponseOnce ( JSON . stringify ( { links : [ { rel : 'search' , method : 'POST' } ] } ) ) ;
1516 const stacApi = new StacApi ( 'https://fake-stac-api.net' ) ;
1617 beforeEach ( ( ) => fetch . resetMocks ( ) ) ;
1718
@@ -410,9 +411,92 @@ describe('useStacSearch', () => {
410411 expect ( result . current . results ) . toEqual ( { data : '12345' } ) ;
411412 expect ( result . current . bbox ) . toEqual ( bbox ) ;
412413
414+ fetch . mockResponseOnce ( JSON . stringify ( { links : [ { rel : 'search' , method : 'POST' } ] } ) ) ;
413415 const newStac = new StacApi ( 'https://otherstack.com' ) ;
414416 rerender ( { stacApi : newStac } ) ;
415417 expect ( result . current . results ) . toBeUndefined ( ) ;
416418 expect ( result . current . bbox ) . toBeUndefined ( ) ;
417419 } ) ;
418420} ) ;
421+
422+ describe ( 'useStacSearch — API supports GET' , ( ) => {
423+ fetch . mockResponseOnce ( JSON . stringify ( { links : [ { rel : 'search' , method : 'GET' } ] } ) ) ;
424+ const stacApi = new StacApi ( 'https://fake-stac-api.net' ) ;
425+ beforeEach ( ( ) => fetch . resetMocks ( ) ) ;
426+
427+ it ( 'includes Bbox in search' , async ( ) => {
428+ fetch . mockResponseOnce ( JSON . stringify ( { data : '12345' } ) ) ;
429+
430+ const { result, waitForNextUpdate } = renderHook (
431+ ( ) => useStacSearch ( stacApi )
432+ ) ;
433+
434+ act ( ( ) => result . current . setBbox ( [ - 0.59 , 51.24 , 0.30 , 51.74 ] ) ) ;
435+ act ( ( ) => result . current . submit ( ) ) ;
436+ await waitForNextUpdate ( ) ;
437+
438+ expect ( fetch . mock . calls [ 0 ] [ 0 ] ) . toEqual ( 'https://fake-stac-api.net/search?bbox=-0.59%2C51.24%2C0.3%2C51.74&limit=25' ) ;
439+ expect ( result . current . results ) . toEqual ( { data : '12345' } ) ;
440+ } ) ;
441+
442+ it ( 'includes Collections in search' , async ( ) => {
443+ fetch . mockResponseOnce ( JSON . stringify ( { data : '12345' } ) ) ;
444+
445+ const { result, waitForNextUpdate } = renderHook (
446+ ( ) => useStacSearch ( stacApi )
447+ ) ;
448+
449+ act ( ( ) => result . current . setCollections ( [ 'wildfire' , 'surface_temp' ] ) ) ;
450+ act ( ( ) => result . current . submit ( ) ) ;
451+ await waitForNextUpdate ( ) ;
452+
453+ expect ( fetch . mock . calls [ 0 ] [ 0 ] ) . toEqual ( 'https://fake-stac-api.net/search?collections=wildfire%2Csurface_temp&limit=25' ) ;
454+ expect ( result . current . results ) . toEqual ( { data : '12345' } ) ;
455+ } ) ;
456+
457+ it ( 'includes date range in search' , async ( ) => {
458+ fetch . mockResponseOnce ( JSON . stringify ( { data : '12345' } ) ) ;
459+
460+ const { result, waitForNextUpdate } = renderHook (
461+ ( ) => useStacSearch ( stacApi )
462+ ) ;
463+
464+ act ( ( ) => result . current . setDateRangeFrom ( '2022-01-17' ) ) ;
465+ act ( ( ) => result . current . setDateRangeTo ( '2022-05-17' ) ) ;
466+ act ( ( ) => result . current . submit ( ) ) ;
467+ await waitForNextUpdate ( ) ;
468+
469+ expect ( fetch . mock . calls [ 0 ] [ 0 ] ) . toEqual ( 'https://fake-stac-api.net/search?datetime=2022-01-17%2F2022-05-17&limit=25' ) ;
470+ expect ( result . current . results ) . toEqual ( { data : '12345' } ) ;
471+ } ) ;
472+
473+ it ( 'includes open date range in search (no to-date)' , async ( ) => {
474+ fetch . mockResponseOnce ( JSON . stringify ( { data : '12345' } ) ) ;
475+
476+ const { result, waitForNextUpdate } = renderHook (
477+ ( ) => useStacSearch ( stacApi )
478+ ) ;
479+
480+ act ( ( ) => result . current . setDateRangeFrom ( '2022-01-17' ) ) ;
481+ act ( ( ) => result . current . submit ( ) ) ;
482+ await waitForNextUpdate ( ) ;
483+
484+ expect ( fetch . mock . calls [ 0 ] [ 0 ] ) . toEqual ( 'https://fake-stac-api.net/search?datetime=2022-01-17%2F..&limit=25' ) ;
485+ expect ( result . current . results ) . toEqual ( { data : '12345' } ) ;
486+ } ) ;
487+
488+ it ( 'includes open date range in search (no from-date)' , async ( ) => {
489+ fetch . mockResponseOnce ( JSON . stringify ( { data : '12345' } ) ) ;
490+
491+ const { result, waitForNextUpdate } = renderHook (
492+ ( ) => useStacSearch ( stacApi )
493+ ) ;
494+
495+ act ( ( ) => result . current . setDateRangeTo ( '2022-05-17' ) ) ;
496+ act ( ( ) => result . current . submit ( ) ) ;
497+ await waitForNextUpdate ( ) ;
498+
499+ expect ( fetch . mock . calls [ 0 ] [ 0 ] ) . toEqual ( 'https://fake-stac-api.net/search?datetime=..%2F2022-05-17&limit=25' ) ;
500+ expect ( result . current . results ) . toEqual ( { data : '12345' } ) ;
501+ } ) ;
502+ } ) ;
0 commit comments