import axios from 'axios' ; import type { AxiosInstance } from 'axios' ; import { delay } from '../../../src' ; import { Geocoder } from '../../../src/geocoder' ; import { GoogleMapsProvider } from '../../../src/provider' ; import { distanceQueryFixture , geocodeQueryFixture , geocodeQueryFixtureForAustralia , geocodeQueryFixtureForCountryWithoutStateCode , reverseQueryFixture , suggestQueryFixture , } from '../../fixture/model/query.fixture' ; import { providerParsedPlaceDetailsResponse , providerPlaceDetailsQueryFixture } from '../../fixture/provider/google.fixture' ; import type { Location } from '../../../src/model' ; import type { GeocodeQueryInterface , PlaceDetailsQueryInterface , ReverseQueryInterface , SuggestQueryInterface } from '../../../src/interface' ; import type { Distance , DistanceQueryInterface } from '../../../src' ; describe ( 'GoogleMapsProvider (integration)' , ( ) => { let client ; let geocoder ; let geocodeQuery ; let geocodeQueryForAustralia ; let geocodeQueryForCountryWithoutStateCode ; let reverseQuery ; let suggestQuery ; let placeDetailsQuery ; let distanceQuery ; beforeEach ( async ( ) => { geocodeQuery = { ... geocodeQueryFixture } ; reverseQuery = { ... reverseQueryFixture } ; suggestQuery = { ... suggestQueryFixture } ; suggestQuery = { ... suggestQueryFixture } ; distanceQuery = { ... distanceQueryFixture } ; geocodeQueryForAustralia = { ... geocodeQueryFixtureForAustralia } ; geocodeQueryForCountryWithoutStateCode = { ... geocodeQueryFixtureForCountryWithoutStateCode } ; placeDetailsQuery = { ... providerPlaceDetailsQueryFixture } ; client = axios . create ( ) ; const provider = new GoogleMapsProvider ( client , `${ process . env . GOOGLE_MAPS_API_KEY }` ) ; geocoder = new Geocoder ( provider ) ; await delay ( 500 ) ; } ) ; describe ( '#geocode' , ( ) => { it ( 'should return expected response' , async ( ) => { return geocoder . geocode ( geocodeQuery ) . should . eventually . be . an ( 'array' ) . with . length ( 1 ) ; } ) ; it ( 'should return expected response for Australia address' , async ( ) => { return geocoder . geocode ( geocodeQueryForAustralia ) . should . eventually . be . an ( 'array' ) . with . length ( 1 ) ; } ) ; it . skip ( 'should return expected response for country without stateCode' , async ( ) => { return geocoder . geocode ( geocodeQueryForCountryWithoutStateCode ) . should . eventually . be . an ( 'array' ) . with . length ( 1 ) ; } ) ; } ) ; describe ( '#reverse' , ( ) => { it ( 'should return expected response' , async ( ) => { return geocoder . reverse ( reverseQuery ) . should . eventually . be . an ( 'array' ) . with . length ( 3 ) ; } ) ; } ) ; describe ( '#suggest' , ( ) => { it ( 'should return expected response' , async ( ) => { return geocoder . suggest ( suggestQuery ) . should . eventually . be . an ( 'array' ) . with . length ( 1 ) ; } ) ; } ) ; describe ( '#placeDetails' , ( ) => { it ( 'should return expected response' , async ( ) => { const location = await geocoder . using ( GoogleMapsProvider ) . placeDetails ( placeDetailsQuery ) ; delete location . raw . id ; delete location . raw . scope ; return location . should . be . deep . eq ( providerParsedPlaceDetailsResponse ) ; } ) ; } ) ; describe ( '#distance' , ( ) => { it ( 'should return expected response' , async ( ) => { const distance = await geocoder . using ( GoogleMapsProvider ) . distance ( distanceQuery ) ; distance . should . have . property ( 'distance' ) ; distance . distance . should . be . a ( 'number' ) ; distance . should . have . property ( 'duration' ) ; distance . duration . should . be . a ( 'number' ) ; distance . should . have . property ( 'provider' ) ; distance . provider . should . be . deep . eq ( GoogleMapsProvider . name ) ; distance . should . have . property ( 'raw' ) ; distance . raw . should . be . an ( 'object' ) ; } ) ; } ) ; } ) ;