import { setAuthToken , isAuthTokenSet } from '../../index' ; import { mockNetwork } from './testUtils.findTiles' ; export const AUTH_TOKEN = 'AUTH_TOKEN' ; export const CATALOG_URL = 'https://services.sentinel-hub.com/api/v1/catalog/search' ; export async function checkIfCorrectEndpointIsUsedFindDatesUTC ( token , fixture , endpoint ) { setAuthToken ( token ) ; expect ( isAuthTokenSet ( ) ) . toBe ( ! ! token ) ; const { fromTime , toTime , bbox , layer } = fixture ; mockNetwork . onAny ( ) . reply ( 200 ) ; try { await layer . findDatesUTC ( bbox , fromTime , toTime , { cache : { expiresIn : 0 } } ) ; } catch ( err ) { } expect ( mockNetwork . history . post . length ) . toBe ( 1 ) ; const request = mockNetwork . history . post [ 0 ] ; expect ( request . url ) . toEqual ( endpoint ) ; } export async function checkRequestFindDatesUTC ( fixtures ) { const { bbox , expectedRequest , fromTime , layer , toTime } = fixtures ; mockNetwork . onAny ( ) . reply ( 200 ) ; try { await layer . findDatesUTC ( bbox , fromTime , toTime , { cache : { expiresIn : 0 } } ) ; } catch ( err ) { } const request = mockNetwork . history . post [ 0 ] ; expect ( request . data ) . not . toBeNull ( ) ; expect ( JSON . parse ( request . data ) ) . toStrictEqual ( expectedRequest ) ; } export async function checkResponseFindDatesUTC ( fixtures ) { const { fromTime , toTime , bbox , layer , mockedResponse , expectedRequest , expectedResult } = fixtures ; mockNetwork . onPost ( ) . replyOnce ( 200 , mockedResponse ) ; const response = await layer . findDatesUTC ( bbox , fromTime , toTime , { cache : { expiresIn : 0 } } ) ; expect ( mockNetwork . history . post . length ) . toBe ( 1 ) ; const request = mockNetwork . history . post [ 0 ] ; expect ( request . data ) . not . toBeNull ( ) ; expect ( JSON . parse ( request . data ) ) . toStrictEqual ( expectedRequest ) ; expect ( response ) . toStrictEqual ( expectedResult ) ; }