@mapbox/mcp-server 0.2.4 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +17 -9
- package/README.md +24 -6
- package/dist/commonjs/config/toolConfig.d.ts +8 -0
- package/dist/commonjs/config/toolConfig.d.ts.map +1 -0
- package/dist/commonjs/config/toolConfig.js +40 -0
- package/dist/commonjs/config/toolConfig.js.map +1 -0
- package/dist/commonjs/index.d.ts +2 -0
- package/dist/{index.d.ts.map → commonjs/index.d.ts.map} +1 -1
- package/dist/commonjs/index.js +39 -0
- package/dist/commonjs/index.js.map +1 -0
- package/dist/{cjs → commonjs}/package.json +1 -1
- package/dist/{tools → commonjs/tools}/MapboxApiBasedTool.d.ts +11 -9
- package/dist/commonjs/tools/MapboxApiBasedTool.d.ts.map +1 -0
- package/dist/commonjs/tools/MapboxApiBasedTool.js +111 -0
- package/dist/commonjs/tools/MapboxApiBasedTool.js.map +1 -0
- package/dist/commonjs/tools/category-list-tool/CategoryListTool.d.ts +28 -0
- package/dist/commonjs/tools/category-list-tool/CategoryListTool.d.ts.map +1 -0
- package/dist/commonjs/tools/category-list-tool/CategoryListTool.js +68 -0
- package/dist/commonjs/tools/category-list-tool/CategoryListTool.js.map +1 -0
- package/dist/{tools → commonjs/tools}/category-search-tool/CategorySearchTool.d.ts +6 -5
- package/dist/commonjs/tools/category-search-tool/CategorySearchTool.d.ts.map +1 -0
- package/dist/commonjs/tools/category-search-tool/CategorySearchTool.js +188 -0
- package/dist/commonjs/tools/category-search-tool/CategorySearchTool.js.map +1 -0
- package/dist/{tools → commonjs/tools}/directions-tool/DirectionsTool.d.ts +3 -2
- package/dist/commonjs/tools/directions-tool/DirectionsTool.d.ts.map +1 -0
- package/dist/commonjs/tools/directions-tool/DirectionsTool.js +385 -0
- package/dist/commonjs/tools/directions-tool/DirectionsTool.js.map +1 -0
- package/dist/{tools → commonjs/tools}/directions-tool/cleanResponseData.d.ts +2 -2
- package/dist/commonjs/tools/directions-tool/cleanResponseData.d.ts.map +1 -0
- package/dist/commonjs/tools/directions-tool/cleanResponseData.js +178 -0
- package/dist/commonjs/tools/directions-tool/cleanResponseData.js.map +1 -0
- package/dist/commonjs/tools/directions-tool/formatIsoDateTime.d.ts.map +1 -0
- package/dist/commonjs/tools/directions-tool/formatIsoDateTime.js +21 -0
- package/dist/commonjs/tools/directions-tool/formatIsoDateTime.js.map +1 -0
- package/dist/{tools → commonjs/tools}/forward-geocode-tool/ForwardGeocodeTool.d.ts +5 -4
- package/dist/commonjs/tools/forward-geocode-tool/ForwardGeocodeTool.d.ts.map +1 -0
- package/dist/commonjs/tools/forward-geocode-tool/ForwardGeocodeTool.js +212 -0
- package/dist/commonjs/tools/forward-geocode-tool/ForwardGeocodeTool.js.map +1 -0
- package/dist/{tools → commonjs/tools}/isochrone-tool/IsochroneTool.d.ts +3 -2
- package/dist/commonjs/tools/isochrone-tool/IsochroneTool.d.ts.map +1 -0
- package/dist/commonjs/tools/isochrone-tool/IsochroneTool.js +118 -0
- package/dist/commonjs/tools/isochrone-tool/IsochroneTool.js.map +1 -0
- package/dist/{tools → commonjs/tools}/matrix-tool/MatrixTool.d.ts +3 -2
- package/dist/commonjs/tools/matrix-tool/MatrixTool.d.ts.map +1 -0
- package/dist/commonjs/tools/matrix-tool/MatrixTool.js +202 -0
- package/dist/commonjs/tools/matrix-tool/MatrixTool.js.map +1 -0
- package/dist/{tools → commonjs/tools}/poi-search-tool/PoiSearchTool.d.ts +5 -4
- package/dist/commonjs/tools/poi-search-tool/PoiSearchTool.d.ts.map +1 -0
- package/dist/commonjs/tools/poi-search-tool/PoiSearchTool.js +231 -0
- package/dist/commonjs/tools/poi-search-tool/PoiSearchTool.js.map +1 -0
- package/dist/{tools → commonjs/tools}/reverse-geocode-tool/ReverseGeocodeTool.d.ts +5 -4
- package/dist/commonjs/tools/reverse-geocode-tool/ReverseGeocodeTool.d.ts.map +1 -0
- package/dist/commonjs/tools/reverse-geocode-tool/ReverseGeocodeTool.js +148 -0
- package/dist/commonjs/tools/reverse-geocode-tool/ReverseGeocodeTool.js.map +1 -0
- package/dist/{tools → commonjs/tools}/static-map-image-tool/StaticMapImageTool.d.ts +3 -2
- package/dist/commonjs/tools/static-map-image-tool/StaticMapImageTool.d.ts.map +1 -0
- package/dist/commonjs/tools/static-map-image-tool/StaticMapImageTool.js +416 -0
- package/dist/commonjs/tools/static-map-image-tool/StaticMapImageTool.js.map +1 -0
- package/dist/{tools → commonjs/tools}/toolRegistry.d.ts +2 -1
- package/dist/commonjs/tools/toolRegistry.d.ts.map +1 -0
- package/dist/commonjs/tools/toolRegistry.js +37 -0
- package/dist/commonjs/tools/toolRegistry.js.map +1 -0
- package/dist/{tools → commonjs/tools}/version-tool/VersionTool.d.ts +1 -1
- package/dist/commonjs/tools/version-tool/VersionTool.d.ts.map +1 -0
- package/dist/commonjs/tools/version-tool/VersionTool.js +52 -0
- package/dist/commonjs/tools/version-tool/VersionTool.js.map +1 -0
- package/dist/commonjs/utils/fetchRequest.d.ts +38 -0
- package/dist/commonjs/utils/fetchRequest.d.ts.map +1 -0
- package/dist/commonjs/utils/fetchRequest.js +110 -0
- package/dist/commonjs/utils/fetchRequest.js.map +1 -0
- package/dist/commonjs/utils/versionUtils-cjs.cjs.map +1 -0
- package/dist/commonjs/utils/versionUtils-cjs.d.cts.map +1 -0
- package/dist/commonjs/utils/versionUtils.d.ts +9 -0
- package/dist/commonjs/utils/versionUtils.js +46 -0
- package/dist/commonjs/version.json +6 -0
- package/dist/esm/config/toolConfig.d.ts +8 -0
- package/dist/esm/config/toolConfig.d.ts.map +1 -0
- package/dist/esm/config/toolConfig.js +36 -0
- package/dist/esm/config/toolConfig.js.map +1 -0
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +37 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +1 -1
- package/dist/esm/tools/MapboxApiBasedTool.d.ts +84 -0
- package/dist/esm/tools/MapboxApiBasedTool.d.ts.map +1 -0
- package/dist/{tools → esm/tools}/MapboxApiBasedTool.js +20 -13
- package/dist/esm/tools/MapboxApiBasedTool.js.map +1 -0
- package/dist/esm/tools/category-list-tool/CategoryListTool.d.ts +28 -0
- package/dist/esm/tools/category-list-tool/CategoryListTool.d.ts.map +1 -0
- package/dist/esm/tools/category-list-tool/CategoryListTool.js +64 -0
- package/dist/esm/tools/category-list-tool/CategoryListTool.js.map +1 -0
- package/dist/esm/tools/category-search-tool/CategorySearchTool.d.ts +89 -0
- package/dist/esm/tools/category-search-tool/CategorySearchTool.d.ts.map +1 -0
- package/dist/esm/tools/category-search-tool/CategorySearchTool.js +184 -0
- package/dist/esm/tools/category-search-tool/CategorySearchTool.js.map +1 -0
- package/dist/esm/tools/directions-tool/DirectionsTool.d.ts +44 -0
- package/dist/esm/tools/directions-tool/DirectionsTool.d.ts.map +1 -0
- package/dist/{tools → esm/tools}/directions-tool/DirectionsTool.js +10 -9
- package/dist/esm/tools/directions-tool/DirectionsTool.js.map +1 -0
- package/dist/esm/tools/directions-tool/cleanResponseData.d.ts +11 -0
- package/dist/esm/tools/directions-tool/cleanResponseData.d.ts.map +1 -0
- package/dist/esm/tools/directions-tool/cleanResponseData.js.map +1 -0
- package/dist/esm/tools/directions-tool/formatIsoDateTime.d.ts +8 -0
- package/dist/esm/tools/directions-tool/formatIsoDateTime.d.ts.map +1 -0
- package/dist/esm/tools/directions-tool/formatIsoDateTime.js.map +1 -0
- package/dist/esm/tools/forward-geocode-tool/ForwardGeocodeTool.d.ts +98 -0
- package/dist/esm/tools/forward-geocode-tool/ForwardGeocodeTool.d.ts.map +1 -0
- package/dist/{tools → esm/tools}/forward-geocode-tool/ForwardGeocodeTool.js +9 -6
- package/dist/esm/tools/forward-geocode-tool/ForwardGeocodeTool.js.map +1 -0
- package/dist/esm/tools/isochrone-tool/IsochroneTool.d.ts +60 -0
- package/dist/esm/tools/isochrone-tool/IsochroneTool.d.ts.map +1 -0
- package/dist/{tools → esm/tools}/isochrone-tool/IsochroneTool.js +8 -5
- package/dist/esm/tools/isochrone-tool/IsochroneTool.js.map +1 -0
- package/dist/esm/tools/matrix-tool/MatrixTool.d.ts +51 -0
- package/dist/esm/tools/matrix-tool/MatrixTool.d.ts.map +1 -0
- package/dist/{tools → esm/tools}/matrix-tool/MatrixTool.js +9 -6
- package/dist/{tools → esm/tools}/matrix-tool/MatrixTool.js.map +1 -1
- package/dist/esm/tools/poi-search-tool/PoiSearchTool.d.ts +119 -0
- package/dist/esm/tools/poi-search-tool/PoiSearchTool.d.ts.map +1 -0
- package/dist/{tools → esm/tools}/poi-search-tool/PoiSearchTool.js +9 -6
- package/dist/esm/tools/poi-search-tool/PoiSearchTool.js.map +1 -0
- package/dist/esm/tools/reverse-geocode-tool/ReverseGeocodeTool.d.ts +46 -0
- package/dist/esm/tools/reverse-geocode-tool/ReverseGeocodeTool.d.ts.map +1 -0
- package/dist/{tools → esm/tools}/reverse-geocode-tool/ReverseGeocodeTool.js +8 -5
- package/dist/esm/tools/reverse-geocode-tool/ReverseGeocodeTool.js.map +1 -0
- package/dist/esm/tools/static-map-image-tool/StaticMapImageTool.d.ts +179 -0
- package/dist/esm/tools/static-map-image-tool/StaticMapImageTool.d.ts.map +1 -0
- package/dist/{tools → esm/tools}/static-map-image-tool/StaticMapImageTool.js +7 -4
- package/dist/esm/tools/static-map-image-tool/StaticMapImageTool.js.map +1 -0
- package/dist/esm/tools/toolRegistry.d.ts +15 -0
- package/dist/esm/tools/toolRegistry.d.ts.map +1 -0
- package/dist/{tools → esm/tools}/toolRegistry.js +2 -0
- package/dist/esm/tools/toolRegistry.js.map +1 -0
- package/dist/esm/tools/version-tool/VersionTool.d.ts +18 -0
- package/dist/esm/tools/version-tool/VersionTool.d.ts.map +1 -0
- package/dist/{tools → esm/tools}/version-tool/VersionTool.js +2 -4
- package/dist/esm/tools/version-tool/VersionTool.js.map +1 -0
- package/dist/esm/utils/fetchRequest.d.ts +38 -0
- package/dist/esm/utils/fetchRequest.d.ts.map +1 -0
- package/dist/esm/utils/fetchRequest.js +104 -0
- package/dist/esm/utils/fetchRequest.js.map +1 -0
- package/dist/esm/utils/versionUtils.d.ts.map +1 -0
- package/dist/{utils → esm/utils}/versionUtils.js +9 -7
- package/dist/esm/utils/versionUtils.js.map +1 -0
- package/dist/esm/version.json +6 -0
- package/package.json +49 -30
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -25
- package/dist/index.js.map +0 -1
- package/dist/tools/MapboxApiBasedTool.d.ts.map +0 -1
- package/dist/tools/MapboxApiBasedTool.js.map +0 -1
- package/dist/tools/MapboxApiBasedTool.test.d.ts +0 -2
- package/dist/tools/MapboxApiBasedTool.test.d.ts.map +0 -1
- package/dist/tools/MapboxApiBasedTool.test.js +0 -143
- package/dist/tools/MapboxApiBasedTool.test.js.map +0 -1
- package/dist/tools/category-search-tool/CategorySearchTool.d.ts.map +0 -1
- package/dist/tools/category-search-tool/CategorySearchTool.js +0 -666
- package/dist/tools/category-search-tool/CategorySearchTool.js.map +0 -1
- package/dist/tools/category-search-tool/CategorySearchTool.test.d.ts +0 -2
- package/dist/tools/category-search-tool/CategorySearchTool.test.d.ts.map +0 -1
- package/dist/tools/category-search-tool/CategorySearchTool.test.js +0 -369
- package/dist/tools/category-search-tool/CategorySearchTool.test.js.map +0 -1
- package/dist/tools/directions-tool/DirectionsTool.d.ts.map +0 -1
- package/dist/tools/directions-tool/DirectionsTool.js.map +0 -1
- package/dist/tools/directions-tool/DirectionsTool.test.d.ts +0 -2
- package/dist/tools/directions-tool/DirectionsTool.test.d.ts.map +0 -1
- package/dist/tools/directions-tool/DirectionsTool.test.js +0 -822
- package/dist/tools/directions-tool/DirectionsTool.test.js.map +0 -1
- package/dist/tools/directions-tool/cleanResponseData.d.ts.map +0 -1
- package/dist/tools/directions-tool/cleanResponseData.js.map +0 -1
- package/dist/tools/directions-tool/cleanResponseData.test.d.ts +0 -2
- package/dist/tools/directions-tool/cleanResponseData.test.d.ts.map +0 -1
- package/dist/tools/directions-tool/cleanResponseData.test.js +0 -295
- package/dist/tools/directions-tool/cleanResponseData.test.js.map +0 -1
- package/dist/tools/directions-tool/formatIsoDateTime.d.ts.map +0 -1
- package/dist/tools/directions-tool/formatIsoDateTime.js.map +0 -1
- package/dist/tools/directions-tool/formatIsoDateTime.test.d.ts +0 -2
- package/dist/tools/directions-tool/formatIsoDateTime.test.d.ts.map +0 -1
- package/dist/tools/directions-tool/formatIsoDateTime.test.js +0 -26
- package/dist/tools/directions-tool/formatIsoDateTime.test.js.map +0 -1
- package/dist/tools/forward-geocode-tool/ForwardGeocodeTool.d.ts.map +0 -1
- package/dist/tools/forward-geocode-tool/ForwardGeocodeTool.js.map +0 -1
- package/dist/tools/forward-geocode-tool/ForwardGeocodeTool.test.d.ts +0 -2
- package/dist/tools/forward-geocode-tool/ForwardGeocodeTool.test.d.ts.map +0 -1
- package/dist/tools/forward-geocode-tool/ForwardGeocodeTool.test.js +0 -415
- package/dist/tools/forward-geocode-tool/ForwardGeocodeTool.test.js.map +0 -1
- package/dist/tools/isochrone-tool/IsochroneTool.d.ts.map +0 -1
- package/dist/tools/isochrone-tool/IsochroneTool.js.map +0 -1
- package/dist/tools/isochrone-tool/IsochroneTool.test.d.ts +0 -2
- package/dist/tools/isochrone-tool/IsochroneTool.test.d.ts.map +0 -1
- package/dist/tools/isochrone-tool/IsochroneTool.test.js +0 -111
- package/dist/tools/isochrone-tool/IsochroneTool.test.js.map +0 -1
- package/dist/tools/matrix-tool/MatrixTool.d.ts.map +0 -1
- package/dist/tools/matrix-tool/MatrixTool.test.d.ts +0 -2
- package/dist/tools/matrix-tool/MatrixTool.test.d.ts.map +0 -1
- package/dist/tools/matrix-tool/MatrixTool.test.js +0 -816
- package/dist/tools/matrix-tool/MatrixTool.test.js.map +0 -1
- package/dist/tools/poi-search-tool/PoiSearchTool.d.ts.map +0 -1
- package/dist/tools/poi-search-tool/PoiSearchTool.js.map +0 -1
- package/dist/tools/poi-search-tool/PoiSearchTool.test.d.ts +0 -2
- package/dist/tools/poi-search-tool/PoiSearchTool.test.d.ts.map +0 -1
- package/dist/tools/poi-search-tool/PoiSearchTool.test.js +0 -418
- package/dist/tools/poi-search-tool/PoiSearchTool.test.js.map +0 -1
- package/dist/tools/reverse-geocode-tool/ReverseGeocodeTool.d.ts.map +0 -1
- package/dist/tools/reverse-geocode-tool/ReverseGeocodeTool.js.map +0 -1
- package/dist/tools/reverse-geocode-tool/ReverseGeocodeTool.test.d.ts +0 -2
- package/dist/tools/reverse-geocode-tool/ReverseGeocodeTool.test.d.ts.map +0 -1
- package/dist/tools/reverse-geocode-tool/ReverseGeocodeTool.test.js +0 -403
- package/dist/tools/reverse-geocode-tool/ReverseGeocodeTool.test.js.map +0 -1
- package/dist/tools/schema-validation.test.d.ts +0 -2
- package/dist/tools/schema-validation.test.d.ts.map +0 -1
- package/dist/tools/schema-validation.test.js +0 -75
- package/dist/tools/schema-validation.test.js.map +0 -1
- package/dist/tools/static-map-image-tool/StaticMapImageTool.d.ts.map +0 -1
- package/dist/tools/static-map-image-tool/StaticMapImageTool.js.map +0 -1
- package/dist/tools/static-map-image-tool/StaticMapImageTool.test.d.ts +0 -2
- package/dist/tools/static-map-image-tool/StaticMapImageTool.test.d.ts.map +0 -1
- package/dist/tools/static-map-image-tool/StaticMapImageTool.test.js +0 -441
- package/dist/tools/static-map-image-tool/StaticMapImageTool.test.js.map +0 -1
- package/dist/tools/tool-naming-convention.test.d.ts +0 -2
- package/dist/tools/tool-naming-convention.test.d.ts.map +0 -1
- package/dist/tools/tool-naming-convention.test.js +0 -43
- package/dist/tools/tool-naming-convention.test.js.map +0 -1
- package/dist/tools/toolRegistry.d.ts.map +0 -1
- package/dist/tools/toolRegistry.js.map +0 -1
- package/dist/tools/version-tool/VersionTool.d.ts.map +0 -1
- package/dist/tools/version-tool/VersionTool.js.map +0 -1
- package/dist/tools/version-tool/VersionTool.test.d.ts +0 -2
- package/dist/tools/version-tool/VersionTool.test.d.ts.map +0 -1
- package/dist/tools/version-tool/VersionTool.test.js +0 -49
- package/dist/tools/version-tool/VersionTool.test.js.map +0 -1
- package/dist/utils/requestUtils.d.ts +0 -6
- package/dist/utils/requestUtils.d.ts.map +0 -1
- package/dist/utils/requestUtils.js +0 -60
- package/dist/utils/requestUtils.js.map +0 -1
- package/dist/utils/requestUtils.test-helpers.d.ts +0 -3
- package/dist/utils/requestUtils.test-helpers.d.ts.map +0 -1
- package/dist/utils/requestUtils.test-helpers.js +0 -32
- package/dist/utils/requestUtils.test-helpers.js.map +0 -1
- package/dist/utils/requestUtils.test.d.ts +0 -2
- package/dist/utils/requestUtils.test.d.ts.map +0 -1
- package/dist/utils/requestUtils.test.js +0 -115
- package/dist/utils/requestUtils.test.js.map +0 -1
- package/dist/utils/versionUtils.d.ts.map +0 -1
- package/dist/utils/versionUtils.js.map +0 -1
- package/dist/version.json +0 -6
- /package/dist/{tools → commonjs/tools}/directions-tool/formatIsoDateTime.d.ts +0 -0
- /package/dist/{tools → esm/tools}/directions-tool/cleanResponseData.js +0 -0
- /package/dist/{tools → esm/tools}/directions-tool/formatIsoDateTime.js +0 -0
- /package/dist/{utils → esm/utils}/versionUtils.d.ts +0 -0
|
@@ -1,822 +0,0 @@
|
|
|
1
|
-
process.env.MAPBOX_ACCESS_TOKEN = 'test.token.signature';
|
|
2
|
-
import { cleanup } from '../../utils/requestUtils.js';
|
|
3
|
-
import { setupFetch, assertHeadersSent } from '../../utils/requestUtils.test-helpers.js';
|
|
4
|
-
import { DirectionsTool } from './DirectionsTool.js';
|
|
5
|
-
import * as cleanResponseModule from './cleanResponseData.js';
|
|
6
|
-
describe('DirectionsTool', () => {
|
|
7
|
-
beforeEach(() => {
|
|
8
|
-
// Mock the cleanResponseData function to return data unchanged, this make testing much easier
|
|
9
|
-
// There should be separate test suits for `cleanResponseData`
|
|
10
|
-
jest
|
|
11
|
-
.spyOn(cleanResponseModule, 'cleanResponseData')
|
|
12
|
-
.mockImplementation((_, data) => data);
|
|
13
|
-
// Enable verbose errors for testing
|
|
14
|
-
process.env.VERBOSE_ERRORS = 'true';
|
|
15
|
-
});
|
|
16
|
-
afterEach(() => {
|
|
17
|
-
jest.restoreAllMocks();
|
|
18
|
-
cleanup();
|
|
19
|
-
});
|
|
20
|
-
it('sends custom header', async () => {
|
|
21
|
-
const mockFetch = setupFetch();
|
|
22
|
-
await new DirectionsTool().run({
|
|
23
|
-
coordinates: [
|
|
24
|
-
[-74.102094, 40.692815],
|
|
25
|
-
[-74.1022094, 40.792815]
|
|
26
|
-
]
|
|
27
|
-
});
|
|
28
|
-
assertHeadersSent(mockFetch);
|
|
29
|
-
});
|
|
30
|
-
it('constructs correct URL with required parameters', async () => {
|
|
31
|
-
const mockFetch = setupFetch();
|
|
32
|
-
await new DirectionsTool().run({
|
|
33
|
-
coordinates: [
|
|
34
|
-
[-73.989, 40.733],
|
|
35
|
-
[-73.979, 40.743]
|
|
36
|
-
]
|
|
37
|
-
});
|
|
38
|
-
const calledUrl = mockFetch.mock.calls[0][0];
|
|
39
|
-
expect(calledUrl).toContain('directions/v5/mapbox/driving-traffic');
|
|
40
|
-
expect(calledUrl).toContain('-73.989%2C40.733%3B-73.979%2C40.743');
|
|
41
|
-
expect(calledUrl).toContain('access_token=');
|
|
42
|
-
assertHeadersSent(mockFetch);
|
|
43
|
-
});
|
|
44
|
-
it('includes all optional parameters in URL', async () => {
|
|
45
|
-
const mockFetch = setupFetch();
|
|
46
|
-
await new DirectionsTool().run({
|
|
47
|
-
coordinates: [
|
|
48
|
-
[-122.42, 37.78],
|
|
49
|
-
[-122.4, 37.79],
|
|
50
|
-
[-122.39, 37.77]
|
|
51
|
-
],
|
|
52
|
-
routing_profile: 'walking',
|
|
53
|
-
geometries: 'geojson',
|
|
54
|
-
alternatives: true,
|
|
55
|
-
exclude: 'ferry'
|
|
56
|
-
});
|
|
57
|
-
const calledUrl = mockFetch.mock.calls[0][0];
|
|
58
|
-
expect(calledUrl).toContain('directions/v5/mapbox/walking');
|
|
59
|
-
expect(calledUrl).toContain('-122.42%2C37.78%3B-122.4%2C37.79%3B-122.39%2C37.77');
|
|
60
|
-
expect(calledUrl).toContain('geometries=geojson');
|
|
61
|
-
expect(calledUrl).toContain('alternatives=true');
|
|
62
|
-
expect(calledUrl).toContain('annotations=distance%2Cspeed');
|
|
63
|
-
expect(calledUrl).toContain('overview=full');
|
|
64
|
-
expect(calledUrl).toContain('exclude=ferry');
|
|
65
|
-
assertHeadersSent(mockFetch);
|
|
66
|
-
});
|
|
67
|
-
it('uses default parameters when not specified', async () => {
|
|
68
|
-
const mockFetch = setupFetch();
|
|
69
|
-
await new DirectionsTool().run({
|
|
70
|
-
coordinates: [
|
|
71
|
-
[-118.24, 34.05],
|
|
72
|
-
[-118.3, 34.02]
|
|
73
|
-
]
|
|
74
|
-
});
|
|
75
|
-
const calledUrl = mockFetch.mock.calls[0][0];
|
|
76
|
-
expect(calledUrl).toContain('directions/v5/mapbox/driving-traffic');
|
|
77
|
-
expect(calledUrl).not.toContain('geometries=');
|
|
78
|
-
expect(calledUrl).toContain('alternatives=false');
|
|
79
|
-
expect(calledUrl).toContain('annotations=distance%2Ccongestion%2Cspeed');
|
|
80
|
-
expect(calledUrl).not.toContain('exclude=');
|
|
81
|
-
assertHeadersSent(mockFetch);
|
|
82
|
-
});
|
|
83
|
-
it('handles geometries=none', async () => {
|
|
84
|
-
const mockFetch = setupFetch();
|
|
85
|
-
await new DirectionsTool().run({
|
|
86
|
-
coordinates: [
|
|
87
|
-
[-118.24, 34.05],
|
|
88
|
-
[-118.3, 34.02]
|
|
89
|
-
],
|
|
90
|
-
geometries: 'none'
|
|
91
|
-
});
|
|
92
|
-
const calledUrl = mockFetch.mock.calls[0][0];
|
|
93
|
-
expect(calledUrl).toContain('directions/v5/mapbox/driving-traffic');
|
|
94
|
-
expect(calledUrl).not.toContain('geometries=');
|
|
95
|
-
expect(calledUrl).toContain('alternatives=false');
|
|
96
|
-
expect(calledUrl).toContain('annotations=distance%2Ccongestion%2Cspeed');
|
|
97
|
-
expect(calledUrl).not.toContain('exclude=');
|
|
98
|
-
assertHeadersSent(mockFetch);
|
|
99
|
-
});
|
|
100
|
-
it('handles exclude parameter with point format', async () => {
|
|
101
|
-
const mockFetch = setupFetch();
|
|
102
|
-
await new DirectionsTool().run({
|
|
103
|
-
coordinates: [
|
|
104
|
-
[-74.0, 40.7],
|
|
105
|
-
[-73.9, 40.8]
|
|
106
|
-
],
|
|
107
|
-
exclude: 'toll,point(-73.95 40.75)'
|
|
108
|
-
});
|
|
109
|
-
const calledUrl = mockFetch.mock.calls[0][0];
|
|
110
|
-
const comma = '%2C';
|
|
111
|
-
const space = '%20';
|
|
112
|
-
const openPar = '%28';
|
|
113
|
-
const closePar = '%29';
|
|
114
|
-
expect(calledUrl).toContain(`exclude=toll${comma}point${openPar}-73.95${space}40.75${closePar}`);
|
|
115
|
-
assertHeadersSent(mockFetch);
|
|
116
|
-
});
|
|
117
|
-
it('handles fetch errors gracefully', async () => {
|
|
118
|
-
const mockFetch = setupFetch({
|
|
119
|
-
ok: false,
|
|
120
|
-
status: 404,
|
|
121
|
-
statusText: 'Not Found'
|
|
122
|
-
});
|
|
123
|
-
const result = await new DirectionsTool().run({
|
|
124
|
-
coordinates: [
|
|
125
|
-
[-73.989, 40.733],
|
|
126
|
-
[-73.979, 40.743]
|
|
127
|
-
]
|
|
128
|
-
});
|
|
129
|
-
expect(result.isError).toBe(true);
|
|
130
|
-
expect(result.content[0]).toMatchObject({
|
|
131
|
-
type: 'text',
|
|
132
|
-
text: 'Request failed with status 404: Not Found'
|
|
133
|
-
});
|
|
134
|
-
assertHeadersSent(mockFetch);
|
|
135
|
-
});
|
|
136
|
-
it('validates coordinates constraints - minimum required', async () => {
|
|
137
|
-
const tool = new DirectionsTool();
|
|
138
|
-
// Test with only one coordinate (invalid)
|
|
139
|
-
await expect(tool.run({
|
|
140
|
-
coordinates: [[-73.989, 40.733]]
|
|
141
|
-
})).resolves.toMatchObject({
|
|
142
|
-
isError: true
|
|
143
|
-
});
|
|
144
|
-
// Test with zero coordinates (invalid)
|
|
145
|
-
await expect(tool.run({
|
|
146
|
-
coordinates: []
|
|
147
|
-
})).resolves.toMatchObject({
|
|
148
|
-
isError: true
|
|
149
|
-
});
|
|
150
|
-
});
|
|
151
|
-
it('validates coordinates constraints - maximum allowed', async () => {
|
|
152
|
-
const tool = new DirectionsTool();
|
|
153
|
-
// Create an array of 26 coordinates (one more than allowed)
|
|
154
|
-
const tooManyCoords = Array(26).fill([-73.989, 40.733]);
|
|
155
|
-
await expect(tool.run({
|
|
156
|
-
coordinates: tooManyCoords
|
|
157
|
-
})).resolves.toMatchObject({
|
|
158
|
-
isError: true
|
|
159
|
-
});
|
|
160
|
-
});
|
|
161
|
-
it('successfully processes exactly 2 coordinates (minimum allowed)', async () => {
|
|
162
|
-
const mockFetch = setupFetch();
|
|
163
|
-
await new DirectionsTool().run({
|
|
164
|
-
coordinates: [
|
|
165
|
-
[-73.989, 40.733],
|
|
166
|
-
[-73.979, 40.743]
|
|
167
|
-
]
|
|
168
|
-
});
|
|
169
|
-
const calledUrl = mockFetch.mock.calls[0][0];
|
|
170
|
-
expect(calledUrl).toContain('-73.989%2C40.733%3B-73.979%2C40.743');
|
|
171
|
-
assertHeadersSent(mockFetch);
|
|
172
|
-
});
|
|
173
|
-
it('successfully processes exactly 25 coordinates (maximum allowed)', async () => {
|
|
174
|
-
const mockFetch = setupFetch();
|
|
175
|
-
// Create an array of exactly 25 coordinates (maximum allowed)
|
|
176
|
-
const maxCoords = Array(25)
|
|
177
|
-
.fill(0)
|
|
178
|
-
.map((_, i) => [-74 + i * 0.01, 40 + i * 0.01]);
|
|
179
|
-
await new DirectionsTool().run({
|
|
180
|
-
coordinates: maxCoords
|
|
181
|
-
});
|
|
182
|
-
const calledUrl = mockFetch.mock.calls[0][0];
|
|
183
|
-
// Check that all coordinates are properly encoded
|
|
184
|
-
for (let i = 0; i < maxCoords.length; i++) {
|
|
185
|
-
const [lng, lat] = maxCoords[i];
|
|
186
|
-
const semicolon = i < 24 ? '%3B' : '';
|
|
187
|
-
const expectedCoord = `${lng}%2C${lat}` + semicolon;
|
|
188
|
-
expect(calledUrl).toContain(expectedCoord);
|
|
189
|
-
}
|
|
190
|
-
assertHeadersSent(mockFetch);
|
|
191
|
-
});
|
|
192
|
-
describe('exclude parameter and routing profile validations', () => {
|
|
193
|
-
it('accepts driving-specific exclusions with driving profiles', async () => {
|
|
194
|
-
const mockFetch = setupFetch();
|
|
195
|
-
const tool = new DirectionsTool();
|
|
196
|
-
// Test with driving profile
|
|
197
|
-
await expect(tool.run({
|
|
198
|
-
coordinates: [
|
|
199
|
-
[-73.989, 40.733],
|
|
200
|
-
[-73.979, 40.743]
|
|
201
|
-
],
|
|
202
|
-
routing_profile: 'driving',
|
|
203
|
-
exclude: 'toll,motorway,unpaved'
|
|
204
|
-
})).resolves.not.toMatchObject({
|
|
205
|
-
isError: true
|
|
206
|
-
});
|
|
207
|
-
// Test with driving-traffic profile
|
|
208
|
-
await expect(tool.run({
|
|
209
|
-
coordinates: [
|
|
210
|
-
[-73.989, 40.733],
|
|
211
|
-
[-73.979, 40.743]
|
|
212
|
-
],
|
|
213
|
-
routing_profile: 'driving-traffic',
|
|
214
|
-
exclude: 'tunnel,country_border,state_border'
|
|
215
|
-
})).resolves.not.toMatchObject({
|
|
216
|
-
isError: true
|
|
217
|
-
});
|
|
218
|
-
});
|
|
219
|
-
it('rejects driving-specific exclusions with non-driving profiles', async () => {
|
|
220
|
-
const tool = new DirectionsTool();
|
|
221
|
-
// Test with walking profile
|
|
222
|
-
await expect(tool.run({
|
|
223
|
-
coordinates: [
|
|
224
|
-
[-73.989, 40.733],
|
|
225
|
-
[-73.979, 40.743]
|
|
226
|
-
],
|
|
227
|
-
routing_profile: 'walking',
|
|
228
|
-
exclude: 'toll'
|
|
229
|
-
})).resolves.toMatchObject({
|
|
230
|
-
isError: true
|
|
231
|
-
});
|
|
232
|
-
// Test with cycling profile
|
|
233
|
-
await expect(tool.run({
|
|
234
|
-
coordinates: [
|
|
235
|
-
[-73.989, 40.733],
|
|
236
|
-
[-73.979, 40.743]
|
|
237
|
-
],
|
|
238
|
-
routing_profile: 'cycling',
|
|
239
|
-
exclude: 'motorway'
|
|
240
|
-
})).resolves.toMatchObject({
|
|
241
|
-
isError: true
|
|
242
|
-
});
|
|
243
|
-
});
|
|
244
|
-
it('accepts common exclusions with all routing profiles', async () => {
|
|
245
|
-
const mockFetch = setupFetch();
|
|
246
|
-
const tool = new DirectionsTool();
|
|
247
|
-
// Test with driving profile
|
|
248
|
-
await expect(tool.run({
|
|
249
|
-
coordinates: [
|
|
250
|
-
[-73.989, 40.733],
|
|
251
|
-
[-73.979, 40.743]
|
|
252
|
-
],
|
|
253
|
-
routing_profile: 'driving',
|
|
254
|
-
exclude: 'ferry'
|
|
255
|
-
})).resolves.not.toMatchObject({
|
|
256
|
-
isError: true
|
|
257
|
-
});
|
|
258
|
-
// Test with walking profile
|
|
259
|
-
await expect(tool.run({
|
|
260
|
-
coordinates: [
|
|
261
|
-
[-73.989, 40.733],
|
|
262
|
-
[-73.979, 40.743]
|
|
263
|
-
],
|
|
264
|
-
routing_profile: 'walking',
|
|
265
|
-
exclude: 'ferry'
|
|
266
|
-
})).resolves.not.toMatchObject({
|
|
267
|
-
isError: true
|
|
268
|
-
});
|
|
269
|
-
// Test with cycling profile
|
|
270
|
-
await expect(tool.run({
|
|
271
|
-
coordinates: [
|
|
272
|
-
[-73.989, 40.733],
|
|
273
|
-
[-73.979, 40.743]
|
|
274
|
-
],
|
|
275
|
-
routing_profile: 'cycling',
|
|
276
|
-
exclude: 'cash_only_tolls'
|
|
277
|
-
})).resolves.not.toMatchObject({
|
|
278
|
-
isError: true
|
|
279
|
-
});
|
|
280
|
-
});
|
|
281
|
-
it('accepts point exclusions with driving profiles and rejects with non-driving profiles', async () => {
|
|
282
|
-
const mockFetch = setupFetch();
|
|
283
|
-
const tool = new DirectionsTool();
|
|
284
|
-
// Test with driving profile - should work
|
|
285
|
-
await expect(tool.run({
|
|
286
|
-
coordinates: [
|
|
287
|
-
[-73.989, 40.733],
|
|
288
|
-
[-73.979, 40.743]
|
|
289
|
-
],
|
|
290
|
-
routing_profile: 'driving',
|
|
291
|
-
exclude: 'point(-73.95 40.75)'
|
|
292
|
-
})).resolves.not.toMatchObject({
|
|
293
|
-
isError: true
|
|
294
|
-
});
|
|
295
|
-
// Test with walking profile - should fail
|
|
296
|
-
await expect(tool.run({
|
|
297
|
-
coordinates: [
|
|
298
|
-
[-73.989, 40.733],
|
|
299
|
-
[-73.979, 40.743]
|
|
300
|
-
],
|
|
301
|
-
routing_profile: 'walking',
|
|
302
|
-
exclude: 'point(-73.95 40.75)'
|
|
303
|
-
})).resolves.toMatchObject({
|
|
304
|
-
isError: true
|
|
305
|
-
});
|
|
306
|
-
// Test with cycling profile - should fail
|
|
307
|
-
await expect(tool.run({
|
|
308
|
-
coordinates: [
|
|
309
|
-
[-73.989, 40.733],
|
|
310
|
-
[-73.979, 40.743]
|
|
311
|
-
],
|
|
312
|
-
routing_profile: 'cycling',
|
|
313
|
-
exclude: 'point(-73.95 40.75)'
|
|
314
|
-
})).resolves.toMatchObject({
|
|
315
|
-
isError: true
|
|
316
|
-
});
|
|
317
|
-
});
|
|
318
|
-
it('handles multiple exclusions in a single request correctly', async () => {
|
|
319
|
-
const mockFetch = setupFetch();
|
|
320
|
-
const tool = new DirectionsTool();
|
|
321
|
-
// All valid exclusions for driving profile
|
|
322
|
-
await expect(tool.run({
|
|
323
|
-
coordinates: [
|
|
324
|
-
[-73.989, 40.733],
|
|
325
|
-
[-73.979, 40.743]
|
|
326
|
-
],
|
|
327
|
-
routing_profile: 'driving',
|
|
328
|
-
exclude: 'toll,motorway,ferry,cash_only_tolls,point(-73.95 40.75)'
|
|
329
|
-
})).resolves.not.toMatchObject({
|
|
330
|
-
isError: true
|
|
331
|
-
});
|
|
332
|
-
// Mixed valid and invalid exclusions (ferry is valid for walking, toll is not)
|
|
333
|
-
await expect(tool.run({
|
|
334
|
-
coordinates: [
|
|
335
|
-
[-73.989, 40.733],
|
|
336
|
-
[-73.979, 40.743]
|
|
337
|
-
],
|
|
338
|
-
routing_profile: 'walking',
|
|
339
|
-
exclude: 'ferry,toll'
|
|
340
|
-
})).resolves.toMatchObject({
|
|
341
|
-
isError: true
|
|
342
|
-
});
|
|
343
|
-
// All valid exclusions for cycling profile
|
|
344
|
-
await expect(tool.run({
|
|
345
|
-
coordinates: [
|
|
346
|
-
[-73.989, 40.733],
|
|
347
|
-
[-73.979, 40.743]
|
|
348
|
-
],
|
|
349
|
-
routing_profile: 'cycling',
|
|
350
|
-
exclude: 'ferry,cash_only_tolls'
|
|
351
|
-
})).resolves.not.toMatchObject({
|
|
352
|
-
isError: true
|
|
353
|
-
});
|
|
354
|
-
});
|
|
355
|
-
});
|
|
356
|
-
describe('depart_at parameter validations', () => {
|
|
357
|
-
it('accepts depart_at with driving profiles', async () => {
|
|
358
|
-
const mockFetch = setupFetch();
|
|
359
|
-
const tool = new DirectionsTool();
|
|
360
|
-
const validDateTime = '2025-06-05T10:30:00Z';
|
|
361
|
-
// Test with driving profile
|
|
362
|
-
await expect(tool.run({
|
|
363
|
-
coordinates: [
|
|
364
|
-
[-73.989, 40.733],
|
|
365
|
-
[-73.979, 40.743]
|
|
366
|
-
],
|
|
367
|
-
routing_profile: 'driving',
|
|
368
|
-
depart_at: validDateTime
|
|
369
|
-
})).resolves.not.toMatchObject({
|
|
370
|
-
isError: true
|
|
371
|
-
});
|
|
372
|
-
const calledUrlDriving = mockFetch.mock.calls[0][0];
|
|
373
|
-
expect(calledUrlDriving).toContain(`depart_at=${encodeURIComponent(validDateTime)}`);
|
|
374
|
-
// Test with driving-traffic profile
|
|
375
|
-
await expect(tool.run({
|
|
376
|
-
coordinates: [
|
|
377
|
-
[-73.989, 40.733],
|
|
378
|
-
[-73.979, 40.743]
|
|
379
|
-
],
|
|
380
|
-
routing_profile: 'driving-traffic',
|
|
381
|
-
depart_at: validDateTime
|
|
382
|
-
})).resolves.not.toMatchObject({
|
|
383
|
-
isError: true
|
|
384
|
-
});
|
|
385
|
-
const calledUrlTraffic = mockFetch.mock.calls[1][0];
|
|
386
|
-
expect(calledUrlTraffic).toContain(`depart_at=${encodeURIComponent(validDateTime)}`);
|
|
387
|
-
});
|
|
388
|
-
describe('vehicle dimension parameters validations', () => {
|
|
389
|
-
it('accepts vehicle dimensions with driving profiles', async () => {
|
|
390
|
-
const mockFetch = setupFetch();
|
|
391
|
-
const tool = new DirectionsTool();
|
|
392
|
-
// Test with driving profile
|
|
393
|
-
await expect(tool.run({
|
|
394
|
-
coordinates: [
|
|
395
|
-
[-73.989, 40.733],
|
|
396
|
-
[-73.979, 40.743]
|
|
397
|
-
],
|
|
398
|
-
routing_profile: 'driving',
|
|
399
|
-
max_height: 4.5,
|
|
400
|
-
max_width: 2.5,
|
|
401
|
-
max_weight: 7.8
|
|
402
|
-
})).resolves.not.toMatchObject({
|
|
403
|
-
isError: true
|
|
404
|
-
});
|
|
405
|
-
const calledUrlDriving = mockFetch.mock.calls[0][0];
|
|
406
|
-
expect(calledUrlDriving).toContain('max_height=4.5');
|
|
407
|
-
expect(calledUrlDriving).toContain('max_width=2.5');
|
|
408
|
-
expect(calledUrlDriving).toContain('max_weight=7.8');
|
|
409
|
-
// Test with driving-traffic profile
|
|
410
|
-
await expect(tool.run({
|
|
411
|
-
coordinates: [
|
|
412
|
-
[-73.989, 40.733],
|
|
413
|
-
[-73.979, 40.743]
|
|
414
|
-
],
|
|
415
|
-
routing_profile: 'driving-traffic',
|
|
416
|
-
max_height: 3.2
|
|
417
|
-
})).resolves.not.toMatchObject({
|
|
418
|
-
isError: true
|
|
419
|
-
});
|
|
420
|
-
const calledUrlTraffic = mockFetch.mock.calls[1][0];
|
|
421
|
-
expect(calledUrlTraffic).toContain('max_height=3.2');
|
|
422
|
-
});
|
|
423
|
-
it('rejects vehicle dimensions with non-driving profiles', async () => {
|
|
424
|
-
const tool = new DirectionsTool();
|
|
425
|
-
// Test with walking profile
|
|
426
|
-
await expect(tool.run({
|
|
427
|
-
coordinates: [
|
|
428
|
-
[-73.989, 40.733],
|
|
429
|
-
[-73.979, 40.743]
|
|
430
|
-
],
|
|
431
|
-
routing_profile: 'walking',
|
|
432
|
-
max_height: 4.5
|
|
433
|
-
})).resolves.toMatchObject({
|
|
434
|
-
isError: true
|
|
435
|
-
});
|
|
436
|
-
// Test with cycling profile
|
|
437
|
-
await expect(tool.run({
|
|
438
|
-
coordinates: [
|
|
439
|
-
[-73.989, 40.733],
|
|
440
|
-
[-73.979, 40.743]
|
|
441
|
-
],
|
|
442
|
-
routing_profile: 'cycling',
|
|
443
|
-
max_width: 2.0
|
|
444
|
-
})).resolves.toMatchObject({
|
|
445
|
-
isError: true
|
|
446
|
-
});
|
|
447
|
-
});
|
|
448
|
-
it('validates dimension value ranges', async () => {
|
|
449
|
-
const tool = new DirectionsTool();
|
|
450
|
-
// Test invalid height (too high)
|
|
451
|
-
await expect(tool.run({
|
|
452
|
-
coordinates: [
|
|
453
|
-
[-73.989, 40.733],
|
|
454
|
-
[-73.979, 40.743]
|
|
455
|
-
],
|
|
456
|
-
routing_profile: 'driving',
|
|
457
|
-
max_height: 15.0
|
|
458
|
-
})).resolves.toMatchObject({
|
|
459
|
-
isError: true
|
|
460
|
-
});
|
|
461
|
-
// Test invalid width (negative)
|
|
462
|
-
await expect(tool.run({
|
|
463
|
-
coordinates: [
|
|
464
|
-
[-73.989, 40.733],
|
|
465
|
-
[-73.979, 40.743]
|
|
466
|
-
],
|
|
467
|
-
routing_profile: 'driving',
|
|
468
|
-
max_width: -1.0
|
|
469
|
-
})).resolves.toMatchObject({
|
|
470
|
-
isError: true
|
|
471
|
-
});
|
|
472
|
-
// Test invalid weight (too heavy)
|
|
473
|
-
await expect(tool.run({
|
|
474
|
-
coordinates: [
|
|
475
|
-
[-73.989, 40.733],
|
|
476
|
-
[-73.979, 40.743]
|
|
477
|
-
],
|
|
478
|
-
routing_profile: 'driving',
|
|
479
|
-
max_weight: 150.0
|
|
480
|
-
})).resolves.toMatchObject({
|
|
481
|
-
isError: true
|
|
482
|
-
});
|
|
483
|
-
});
|
|
484
|
-
});
|
|
485
|
-
it('rejects depart_at with non-driving profiles', async () => {
|
|
486
|
-
const tool = new DirectionsTool();
|
|
487
|
-
const validDateTime = '2025-06-05T10:30:00Z';
|
|
488
|
-
// Test with walking profile
|
|
489
|
-
await expect(tool.run({
|
|
490
|
-
coordinates: [
|
|
491
|
-
[-73.989, 40.733],
|
|
492
|
-
[-73.979, 40.743]
|
|
493
|
-
],
|
|
494
|
-
routing_profile: 'walking',
|
|
495
|
-
depart_at: validDateTime
|
|
496
|
-
})).resolves.toMatchObject({
|
|
497
|
-
isError: true
|
|
498
|
-
});
|
|
499
|
-
// Test with cycling profile
|
|
500
|
-
await expect(tool.run({
|
|
501
|
-
coordinates: [
|
|
502
|
-
[-73.989, 40.733],
|
|
503
|
-
[-73.979, 40.743]
|
|
504
|
-
],
|
|
505
|
-
routing_profile: 'cycling',
|
|
506
|
-
depart_at: validDateTime
|
|
507
|
-
})).resolves.toMatchObject({
|
|
508
|
-
isError: true
|
|
509
|
-
});
|
|
510
|
-
});
|
|
511
|
-
it('accepts valid date-time formats', async () => {
|
|
512
|
-
const mockFetch = setupFetch();
|
|
513
|
-
const tool = new DirectionsTool();
|
|
514
|
-
const baseCoordinates = [
|
|
515
|
-
[-73.989, 40.733],
|
|
516
|
-
[-73.979, 40.743]
|
|
517
|
-
];
|
|
518
|
-
// Format 1: YYYY-MM-DDThh:mm:ssZ
|
|
519
|
-
await expect(tool.run({
|
|
520
|
-
coordinates: baseCoordinates,
|
|
521
|
-
depart_at: '2025-06-05T10:30:00Z'
|
|
522
|
-
})).resolves.not.toMatchObject({
|
|
523
|
-
isError: true
|
|
524
|
-
});
|
|
525
|
-
// Format 2: YYYY-MM-DDThh:mmss±hh:mm
|
|
526
|
-
await expect(tool.run({
|
|
527
|
-
coordinates: baseCoordinates,
|
|
528
|
-
depart_at: '2025-06-05T10:30:00+02:00'
|
|
529
|
-
})).resolves.not.toMatchObject({
|
|
530
|
-
isError: true
|
|
531
|
-
});
|
|
532
|
-
// Format 3: YYYY-MM-DDThh:mm
|
|
533
|
-
await expect(tool.run({
|
|
534
|
-
coordinates: baseCoordinates,
|
|
535
|
-
depart_at: '2025-06-05T10:30'
|
|
536
|
-
})).resolves.not.toMatchObject({
|
|
537
|
-
isError: true
|
|
538
|
-
});
|
|
539
|
-
});
|
|
540
|
-
it('rejects invalid date-time formats', async () => {
|
|
541
|
-
const tool = new DirectionsTool();
|
|
542
|
-
const baseCoordinates = [
|
|
543
|
-
[-73.989, 40.733],
|
|
544
|
-
[-73.979, 40.743]
|
|
545
|
-
];
|
|
546
|
-
// Invalid format examples
|
|
547
|
-
const invalidFormats = [
|
|
548
|
-
'2025/06/05 10:30:00', // Wrong delimiter
|
|
549
|
-
'2025-06-05 10:30:00', // Missing T
|
|
550
|
-
'2025-06-05T10:30:00+0200', // Missing colon in timezone
|
|
551
|
-
'25-6-5T10:30:00Z', // Incorrect date format
|
|
552
|
-
'2025-06-05T10:30:00ZZ', // Double timezone
|
|
553
|
-
'2025-06-05', // Missing time
|
|
554
|
-
'10:30:00' // Missing date
|
|
555
|
-
];
|
|
556
|
-
// Test each format separately
|
|
557
|
-
for (let i = 0; i < invalidFormats.length; i++) {
|
|
558
|
-
const format = invalidFormats[i];
|
|
559
|
-
// Test each invalid format individually for better error reporting
|
|
560
|
-
const result = await tool.run({
|
|
561
|
-
coordinates: baseCoordinates,
|
|
562
|
-
depart_at: format
|
|
563
|
-
});
|
|
564
|
-
expect(result.isError).toBe(true);
|
|
565
|
-
}
|
|
566
|
-
});
|
|
567
|
-
it('rejects dates with invalid components', async () => {
|
|
568
|
-
const tool = new DirectionsTool();
|
|
569
|
-
const baseCoordinates = [
|
|
570
|
-
[-73.989, 40.733],
|
|
571
|
-
[-73.979, 40.743]
|
|
572
|
-
];
|
|
573
|
-
// Invalid time components
|
|
574
|
-
const invalidDates = [
|
|
575
|
-
'2025-13-05T10:30:00Z', // Invalid month (13)
|
|
576
|
-
'2025-06-32T10:30:00Z', // Invalid day (32)
|
|
577
|
-
'2025-06-05T24:30:00Z', // Invalid hour (24)
|
|
578
|
-
'2025-06-05T10:60:00Z', // Invalid minute (60)
|
|
579
|
-
'2025-06-05T10:30:60Z' // Invalid second (60)
|
|
580
|
-
];
|
|
581
|
-
for (const date of invalidDates) {
|
|
582
|
-
await expect(tool.run({
|
|
583
|
-
coordinates: baseCoordinates,
|
|
584
|
-
depart_at: date
|
|
585
|
-
})).resolves.toMatchObject({
|
|
586
|
-
isError: true
|
|
587
|
-
});
|
|
588
|
-
}
|
|
589
|
-
});
|
|
590
|
-
it('depart_at accepts and converts YYYY-MM-DDThh:mm:ss format (seconds but no timezone)', async () => {
|
|
591
|
-
const mockFetch = setupFetch();
|
|
592
|
-
const tool = new DirectionsTool();
|
|
593
|
-
const dateTimeWithSeconds = '2025-06-05T10:30:45';
|
|
594
|
-
const expectedConvertedDateTime = '2025-06-05T10:30'; // Without seconds
|
|
595
|
-
await expect(tool.run({
|
|
596
|
-
coordinates: [
|
|
597
|
-
[-73.989, 40.733],
|
|
598
|
-
[-73.979, 40.743]
|
|
599
|
-
],
|
|
600
|
-
depart_at: dateTimeWithSeconds
|
|
601
|
-
})).resolves.not.toMatchObject({
|
|
602
|
-
isError: true
|
|
603
|
-
});
|
|
604
|
-
// Verify the seconds were stripped in the API call
|
|
605
|
-
const calledUrl = mockFetch.mock.calls[0][0];
|
|
606
|
-
expect(calledUrl).toContain(`depart_at=${encodeURIComponent(expectedConvertedDateTime)}`);
|
|
607
|
-
expect(calledUrl).not.toContain(`depart_at=${encodeURIComponent(dateTimeWithSeconds)}`);
|
|
608
|
-
});
|
|
609
|
-
it('arrive_by accepts and converts YYYY-MM-DDThh:mm:ss format (seconds but no timezone)', async () => {
|
|
610
|
-
const mockFetch = setupFetch();
|
|
611
|
-
const tool = new DirectionsTool();
|
|
612
|
-
const dateTimeWithSeconds = '2025-06-05T10:30:45';
|
|
613
|
-
const expectedConvertedDateTime = '2025-06-05T10:30'; // Without seconds
|
|
614
|
-
await expect(tool.run({
|
|
615
|
-
coordinates: [
|
|
616
|
-
[-73.989, 40.733],
|
|
617
|
-
[-73.979, 40.743]
|
|
618
|
-
],
|
|
619
|
-
routing_profile: 'driving',
|
|
620
|
-
arrive_by: dateTimeWithSeconds
|
|
621
|
-
})).resolves.not.toMatchObject({
|
|
622
|
-
isError: true
|
|
623
|
-
});
|
|
624
|
-
// Verify the seconds were stripped in the API call
|
|
625
|
-
const calledUrl = mockFetch.mock.calls[0][0];
|
|
626
|
-
expect(calledUrl).toContain(`arrive_by=${encodeURIComponent(expectedConvertedDateTime)}`);
|
|
627
|
-
expect(calledUrl).not.toContain(`arrive_by=${encodeURIComponent(dateTimeWithSeconds)}`);
|
|
628
|
-
});
|
|
629
|
-
});
|
|
630
|
-
describe('arrive_by parameter validations', () => {
|
|
631
|
-
it('accepts arrive_by with driving profile only', async () => {
|
|
632
|
-
const validDateTime = '2025-06-05T10:30:00Z';
|
|
633
|
-
const mockFetch = setupFetch();
|
|
634
|
-
// Test with driving profile - should work
|
|
635
|
-
await new DirectionsTool().run({
|
|
636
|
-
coordinates: [
|
|
637
|
-
[-74.1, 40.7],
|
|
638
|
-
[-74.2, 40.8]
|
|
639
|
-
],
|
|
640
|
-
routing_profile: 'driving',
|
|
641
|
-
arrive_by: validDateTime
|
|
642
|
-
});
|
|
643
|
-
expect(mockFetch).toHaveBeenCalledTimes(1);
|
|
644
|
-
const calledUrl = mockFetch.mock.calls[0][0];
|
|
645
|
-
expect(calledUrl).toContain(`arrive_by=${encodeURIComponent(validDateTime)}`);
|
|
646
|
-
});
|
|
647
|
-
it('rejects arrive_by with non-driving profiles', async () => {
|
|
648
|
-
const validDateTime = '2025-06-05T10:30:00Z';
|
|
649
|
-
// Test with driving-traffic profile
|
|
650
|
-
const result1 = await new DirectionsTool().run({
|
|
651
|
-
coordinates: [
|
|
652
|
-
[-74.1, 40.7],
|
|
653
|
-
[-74.2, 40.8]
|
|
654
|
-
],
|
|
655
|
-
routing_profile: 'driving-traffic',
|
|
656
|
-
arrive_by: validDateTime
|
|
657
|
-
});
|
|
658
|
-
expect(result1.isError).toBe(true);
|
|
659
|
-
// Test with walking profile
|
|
660
|
-
const result2 = await new DirectionsTool().run({
|
|
661
|
-
coordinates: [
|
|
662
|
-
[-74.1, 40.7],
|
|
663
|
-
[-74.2, 40.8]
|
|
664
|
-
],
|
|
665
|
-
routing_profile: 'walking',
|
|
666
|
-
arrive_by: validDateTime
|
|
667
|
-
});
|
|
668
|
-
expect(result2.isError).toBe(true);
|
|
669
|
-
// Test with cycling profile
|
|
670
|
-
const result3 = await new DirectionsTool().run({
|
|
671
|
-
coordinates: [
|
|
672
|
-
[-74.1, 40.7],
|
|
673
|
-
[-74.2, 40.8]
|
|
674
|
-
],
|
|
675
|
-
routing_profile: 'cycling',
|
|
676
|
-
arrive_by: validDateTime
|
|
677
|
-
});
|
|
678
|
-
expect(result3.isError).toBe(true);
|
|
679
|
-
});
|
|
680
|
-
it('rejects when both arrive_by and depart_at are provided', async () => {
|
|
681
|
-
const result = await new DirectionsTool().run({
|
|
682
|
-
coordinates: [
|
|
683
|
-
[-74.1, 40.7],
|
|
684
|
-
[-74.2, 40.8]
|
|
685
|
-
],
|
|
686
|
-
routing_profile: 'driving',
|
|
687
|
-
depart_at: '2025-06-05T09:30:00Z',
|
|
688
|
-
arrive_by: '2025-06-05T10:30:00Z'
|
|
689
|
-
});
|
|
690
|
-
expect(result.isError).toBe(true);
|
|
691
|
-
});
|
|
692
|
-
it('accepts valid ISO 8601 formats for arrive_by', async () => {
|
|
693
|
-
const mockFetch = setupFetch();
|
|
694
|
-
// Test with Z format
|
|
695
|
-
await new DirectionsTool().run({
|
|
696
|
-
coordinates: [
|
|
697
|
-
[-74.1, 40.7],
|
|
698
|
-
[-74.2, 40.8]
|
|
699
|
-
],
|
|
700
|
-
routing_profile: 'driving',
|
|
701
|
-
arrive_by: '2025-06-05T10:30:00Z'
|
|
702
|
-
});
|
|
703
|
-
expect(mockFetch).toHaveBeenCalledTimes(1);
|
|
704
|
-
mockFetch.mockClear();
|
|
705
|
-
// Test with timezone offset format
|
|
706
|
-
await new DirectionsTool().run({
|
|
707
|
-
coordinates: [
|
|
708
|
-
[-74.1, 40.7],
|
|
709
|
-
[-74.2, 40.8]
|
|
710
|
-
],
|
|
711
|
-
routing_profile: 'driving',
|
|
712
|
-
arrive_by: '2025-06-05T10:30:00+02:00'
|
|
713
|
-
});
|
|
714
|
-
expect(mockFetch).toHaveBeenCalledTimes(1);
|
|
715
|
-
mockFetch.mockClear();
|
|
716
|
-
// Test with simple time format (no seconds, no timezone)
|
|
717
|
-
await new DirectionsTool().run({
|
|
718
|
-
coordinates: [
|
|
719
|
-
[-74.1, 40.7],
|
|
720
|
-
[-74.2, 40.8]
|
|
721
|
-
],
|
|
722
|
-
routing_profile: 'driving',
|
|
723
|
-
arrive_by: '2025-06-05T10:30'
|
|
724
|
-
});
|
|
725
|
-
expect(mockFetch).toHaveBeenCalledTimes(1);
|
|
726
|
-
});
|
|
727
|
-
it('rejects invalid formats for arrive_by', async () => {
|
|
728
|
-
const invalidFormats = [
|
|
729
|
-
// Invalid date formats
|
|
730
|
-
'2025/06/05T10:30:00Z',
|
|
731
|
-
'5-6-2025T10:30:00Z',
|
|
732
|
-
'2025-6-5T10:30:00Z',
|
|
733
|
-
// Invalid time formats
|
|
734
|
-
'2025-06-05T1:30:00Z',
|
|
735
|
-
'2025-06-05T10-30-00Z',
|
|
736
|
-
// Missing T separator
|
|
737
|
-
'2025-06-05 10:30:00Z',
|
|
738
|
-
// Completely wrong formats
|
|
739
|
-
'10:30 June 5, 2025',
|
|
740
|
-
'June 5, 2025 10:30 AM',
|
|
741
|
-
'Tomorrow at 10:30'
|
|
742
|
-
];
|
|
743
|
-
for (const format of invalidFormats) {
|
|
744
|
-
const result = await new DirectionsTool().run({
|
|
745
|
-
coordinates: [
|
|
746
|
-
[-74.1, 40.7],
|
|
747
|
-
[-74.2, 40.8]
|
|
748
|
-
],
|
|
749
|
-
routing_profile: 'driving',
|
|
750
|
-
arrive_by: format
|
|
751
|
-
});
|
|
752
|
-
expect(result.isError).toBe(true);
|
|
753
|
-
}
|
|
754
|
-
});
|
|
755
|
-
it('validates date and time component ranges for arrive_by', async () => {
|
|
756
|
-
const invalidDates = [
|
|
757
|
-
'2025-13-05T10:30:00Z', // Invalid month (13)
|
|
758
|
-
'2025-06-32T10:30:00Z', // Invalid day (32)
|
|
759
|
-
'2025-02-30T10:30:00Z', // Invalid day in February
|
|
760
|
-
'2025-06-05T24:30:00Z', // Invalid hour (24)
|
|
761
|
-
'2025-06-05T10:60:00Z', // Invalid minute (60)
|
|
762
|
-
'2025-06-05T10:30:60Z' // Invalid second (60)
|
|
763
|
-
];
|
|
764
|
-
for (const date of invalidDates) {
|
|
765
|
-
const result = await new DirectionsTool().run({
|
|
766
|
-
coordinates: [
|
|
767
|
-
[-74.1, 40.7],
|
|
768
|
-
[-74.2, 40.8]
|
|
769
|
-
],
|
|
770
|
-
routing_profile: 'driving',
|
|
771
|
-
arrive_by: date
|
|
772
|
-
});
|
|
773
|
-
expect(result.isError).toBe(true);
|
|
774
|
-
}
|
|
775
|
-
});
|
|
776
|
-
});
|
|
777
|
-
it('validates geometries enum values', async () => {
|
|
778
|
-
const tool = new DirectionsTool();
|
|
779
|
-
// Valid values: 'none' and 'geojson'
|
|
780
|
-
await expect(tool.run({
|
|
781
|
-
coordinates: [
|
|
782
|
-
[-73.989, 40.733],
|
|
783
|
-
[-73.979, 40.743]
|
|
784
|
-
],
|
|
785
|
-
geometries: 'none'
|
|
786
|
-
})).resolves.not.toMatchObject({
|
|
787
|
-
isError: true
|
|
788
|
-
});
|
|
789
|
-
await expect(tool.run({
|
|
790
|
-
coordinates: [
|
|
791
|
-
[-73.989, 40.733],
|
|
792
|
-
[-73.979, 40.743]
|
|
793
|
-
],
|
|
794
|
-
geometries: 'geojson'
|
|
795
|
-
})).resolves.not.toMatchObject({
|
|
796
|
-
isError: true
|
|
797
|
-
});
|
|
798
|
-
// Invalid values: 'polyline' and 'polyline6' were removed
|
|
799
|
-
// Test with invalid string values (runtime validation)
|
|
800
|
-
await expect(tool.run({
|
|
801
|
-
coordinates: [
|
|
802
|
-
[-73.989, 40.733],
|
|
803
|
-
[-73.979, 40.743]
|
|
804
|
-
],
|
|
805
|
-
// @ts-ignore - Testing with invalid value for runtime validation
|
|
806
|
-
geometries: 'polyline'
|
|
807
|
-
})).resolves.toMatchObject({
|
|
808
|
-
isError: true
|
|
809
|
-
});
|
|
810
|
-
await expect(tool.run({
|
|
811
|
-
coordinates: [
|
|
812
|
-
[-73.989, 40.733],
|
|
813
|
-
[-73.979, 40.743]
|
|
814
|
-
],
|
|
815
|
-
// @ts-ignore - Testing with invalid value for runtime validation
|
|
816
|
-
geometries: 'polyline6'
|
|
817
|
-
})).resolves.toMatchObject({
|
|
818
|
-
isError: true
|
|
819
|
-
});
|
|
820
|
-
});
|
|
821
|
-
});
|
|
822
|
-
//# sourceMappingURL=DirectionsTool.test.js.map
|