From 33b97b62012bae91dc663fd773dad761aedaba34 Mon Sep 17 00:00:00 2001 From: ZhiHang Li Date: Sun, 28 Jan 2024 01:44:24 +0000 Subject: [PATCH] :white_check_mark: add more test for reverseGeocode --- tools/reverseGeocode.test.ts | 16 +++++++++++----- tools/reverseGeocode.ts | 2 +- tools/showPoisOnMap.ts | 4 ++-- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/tools/reverseGeocode.test.ts b/tools/reverseGeocode.test.ts index 1bea493..51365d1 100644 --- a/tools/reverseGeocode.test.ts +++ b/tools/reverseGeocode.test.ts @@ -1,19 +1,25 @@ import { createReverseGeocode } from './reverseGeocode'; import { expect, it } from 'vitest'; -const reverseGeocode = createReverseGeocode({ - mapboxAccessToken: process.env.MAPBOX_ACCESS_TOKEN || 'YOUR_FALLBACK_MAPBOX_ACCESS_TOKEN', -}); it('should successfully return an address from coordinates', async () => { + const reverseGeocode = createReverseGeocode({ + mapboxAccessToken: process.env.MAPBOX_ACCESS_TOKEN || 'YOUR_FALLBACK_MAPBOX_ACCESS_TOKEN', + }); + const result = await reverseGeocode.execute({ latitude: 40.7128, longitude: -74.006, }); - console.log(result) - expect(result).toMatchObject({ address: expect.stringContaining(','), }); }); + +// throw error if not mapbox access token +it ('should throw an error if no mapbox access token', async () => { + // createReverseGeocode will throw an error if no mapbox access token + expect(() => createReverseGeocode({mapboxAccessToken: ''})).toThrow(); +}); + diff --git a/tools/reverseGeocode.ts b/tools/reverseGeocode.ts index 633d8a1..58c97d9 100644 --- a/tools/reverseGeocode.ts +++ b/tools/reverseGeocode.ts @@ -17,7 +17,7 @@ function createReverseGeocode({ const name = 'reverseGeocode'; const description = ` - Converts latitude and longitude coordinates to a human-readable address using the Mapbox Geocoding API. + Converts latitude and longitude coordinates to a human-readable address using the Mapbox Geocoding API. Returns the address as a string. latitude: The latitude of the location to be geocoded. longitude: The longitude of the location to be geocoded. `; diff --git a/tools/showPoisOnMap.ts b/tools/showPoisOnMap.ts index c36e42a..9466e4f 100644 --- a/tools/showPoisOnMap.ts +++ b/tools/showPoisOnMap.ts @@ -22,9 +22,9 @@ function createShowPoisOnMap({ const name = 'showPoisOnMap'; const description = ` - Displays specific Points of Interest (POIs) on a map using the Mapbox Static API. + Displays specific Points of Interest (POIs) on a map using the Mapbox Static API. Returns a URL to the map image. pois: An array of POIs to be displayed on the map. - zoom: The zoom level for the map depends from the place size. For larger places use min value and for smaller use max. For countries use zoom '1.0'-'3.0'; for national parks, states use '4.0'-'6.0'; landmarks, places or cities use '7.0'-'9.0'. If multiple places are provided, this will automatically set to 'auto'. + zoom: The zoom level for the map depends from the place size. For larger places use min value and for smaller use max. For countries use zoom '1.0'-'3.0'; for national parks, states use '4.0'-'6.0'; landmarks, places or cities use '7.0'-'9.0'. For streets use '10.0'-'20.0'. If multiple places are provided, this will automatically set to 'auto'. mapStyle: The style of the map. Can be 'streets-v12' or 'satellite-streets-v12'. `