Skip to content

Commit

Permalink
✅ add more test for reverseGeocode
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannLai committed Jan 28, 2024
1 parent 055249c commit 33b97b6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
16 changes: 11 additions & 5 deletions tools/reverseGeocode.test.ts
Original file line number Diff line number Diff line change
@@ -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();
});

2 changes: 1 addition & 1 deletion tools/reverseGeocode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
`;
Expand Down
4 changes: 2 additions & 2 deletions tools/showPoisOnMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'.
`

Expand Down

0 comments on commit 33b97b6

Please sign in to comment.