@mapbox/mcp-server 0.2.3 → 0.4.0
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 +10 -4
- package/README.md +10 -10
- 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 +38 -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 +9 -8
- 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/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 +2 -2
- 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 +111 -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 +36 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +1 -1
- package/dist/esm/tools/MapboxApiBasedTool.d.ts +83 -0
- package/dist/esm/tools/MapboxApiBasedTool.d.ts.map +1 -0
- package/dist/{tools → esm/tools}/MapboxApiBasedTool.js +24 -17
- 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 +9 -8
- 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 +8 -5
- 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 +8 -5
- 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 +4 -6
- 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 +105 -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 +4 -2
- package/dist/esm/utils/versionUtils.js.map +1 -0
- package/dist/esm/version.json +6 -0
- package/package.json +45 -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/cleanResponseData.d.ts +0 -0
- /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,816 +0,0 @@
|
|
|
1
|
-
process.env.MAPBOX_ACCESS_TOKEN =
|
|
2
|
-
'eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ0ZXN0In0.signature';
|
|
3
|
-
import { cleanup } from '../../utils/requestUtils.js';
|
|
4
|
-
import { setupFetch, assertHeadersSent } from '../../utils/requestUtils.test-helpers.js';
|
|
5
|
-
import { MatrixTool } from './MatrixTool.js';
|
|
6
|
-
const sampleMatrixResponse = {
|
|
7
|
-
code: 'Ok',
|
|
8
|
-
durations: [
|
|
9
|
-
[0, 573, 1169.5],
|
|
10
|
-
[573, 0, 597],
|
|
11
|
-
[1169.5, 597, 0]
|
|
12
|
-
],
|
|
13
|
-
destinations: [
|
|
14
|
-
{
|
|
15
|
-
name: 'Mission Street',
|
|
16
|
-
location: [-122.418408, 37.751668],
|
|
17
|
-
distance: 5
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
name: '22nd Street',
|
|
21
|
-
location: [-122.422959, 37.755184],
|
|
22
|
-
distance: 8
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
name: '',
|
|
26
|
-
location: [-122.426911, 37.759695],
|
|
27
|
-
distance: 10
|
|
28
|
-
}
|
|
29
|
-
],
|
|
30
|
-
sources: [
|
|
31
|
-
{
|
|
32
|
-
name: 'Mission Street',
|
|
33
|
-
location: [-122.418408, 37.751668],
|
|
34
|
-
distance: 5
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
name: '22nd Street',
|
|
38
|
-
location: [-122.422959, 37.755184],
|
|
39
|
-
distance: 8
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
name: '',
|
|
43
|
-
location: [-122.426911, 37.759695],
|
|
44
|
-
distance: 10
|
|
45
|
-
}
|
|
46
|
-
]
|
|
47
|
-
};
|
|
48
|
-
const sampleMatrixWithDistanceResponse = {
|
|
49
|
-
...sampleMatrixResponse,
|
|
50
|
-
distances: [
|
|
51
|
-
[0, 934.2, 1837.2],
|
|
52
|
-
[934.2, 0, 903],
|
|
53
|
-
[1837.2, 903, 0]
|
|
54
|
-
]
|
|
55
|
-
};
|
|
56
|
-
describe('MatrixTool', () => {
|
|
57
|
-
afterEach(() => {
|
|
58
|
-
jest.restoreAllMocks();
|
|
59
|
-
cleanup();
|
|
60
|
-
});
|
|
61
|
-
it('sends custom header', async () => {
|
|
62
|
-
const mockFetch = setupFetch();
|
|
63
|
-
await new MatrixTool().run({
|
|
64
|
-
coordinates: [
|
|
65
|
-
{ longitude: -74.102094, latitude: 40.692815 },
|
|
66
|
-
{ longitude: -74.1022094, latitude: 40.792815 }
|
|
67
|
-
],
|
|
68
|
-
profile: 'walking'
|
|
69
|
-
});
|
|
70
|
-
assertHeadersSent(mockFetch);
|
|
71
|
-
});
|
|
72
|
-
it('sends request with correct parameters', async () => {
|
|
73
|
-
const mockFetch = setupFetch({
|
|
74
|
-
json: () => Promise.resolve(sampleMatrixResponse)
|
|
75
|
-
});
|
|
76
|
-
const tool = new MatrixTool();
|
|
77
|
-
const result = await tool.run({
|
|
78
|
-
coordinates: [
|
|
79
|
-
{ longitude: -122.42, latitude: 37.78 },
|
|
80
|
-
{ longitude: -122.45, latitude: 37.91 },
|
|
81
|
-
{ longitude: -122.48, latitude: 37.73 }
|
|
82
|
-
],
|
|
83
|
-
profile: 'driving'
|
|
84
|
-
});
|
|
85
|
-
expect(result.is_error).toBe(false);
|
|
86
|
-
expect(mockFetch).toHaveBeenCalledTimes(1);
|
|
87
|
-
// Check that URL contains correct profile and coordinates
|
|
88
|
-
const url = mockFetch.mock.calls[0][0];
|
|
89
|
-
expect(url).toContain('directions-matrix/v1/mapbox/driving/-122.42,37.78;-122.45,37.91;-122.48,37.73');
|
|
90
|
-
expect(url).toContain('access_token=eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ0ZXN0In0.signature');
|
|
91
|
-
assertHeadersSent(mockFetch);
|
|
92
|
-
});
|
|
93
|
-
it('properly includes annotations parameter when specified', async () => {
|
|
94
|
-
const mockFetch = setupFetch({
|
|
95
|
-
json: () => Promise.resolve(sampleMatrixWithDistanceResponse)
|
|
96
|
-
});
|
|
97
|
-
const tool = new MatrixTool();
|
|
98
|
-
await tool.run({
|
|
99
|
-
coordinates: [
|
|
100
|
-
{ longitude: -122.42, latitude: 37.78 },
|
|
101
|
-
{ longitude: -122.45, latitude: 37.91 }
|
|
102
|
-
],
|
|
103
|
-
profile: 'driving',
|
|
104
|
-
annotations: 'duration,distance'
|
|
105
|
-
});
|
|
106
|
-
const url = mockFetch.mock.calls[0][0];
|
|
107
|
-
expect(url).toContain('annotations=duration%2Cdistance');
|
|
108
|
-
});
|
|
109
|
-
it('properly includes approaches parameter when specified', async () => {
|
|
110
|
-
const mockFetch = setupFetch({
|
|
111
|
-
json: () => Promise.resolve(sampleMatrixResponse)
|
|
112
|
-
});
|
|
113
|
-
const tool = new MatrixTool();
|
|
114
|
-
await tool.run({
|
|
115
|
-
coordinates: [
|
|
116
|
-
{ longitude: -122.42, latitude: 37.78 },
|
|
117
|
-
{ longitude: -122.45, latitude: 37.91 },
|
|
118
|
-
{ longitude: -122.48, latitude: 37.73 }
|
|
119
|
-
],
|
|
120
|
-
profile: 'driving',
|
|
121
|
-
approaches: 'curb;unrestricted;curb'
|
|
122
|
-
});
|
|
123
|
-
const url = mockFetch.mock.calls[0][0];
|
|
124
|
-
expect(url).toContain('approaches=curb%3Bunrestricted%3Bcurb');
|
|
125
|
-
});
|
|
126
|
-
it('properly includes bearings parameter when specified', async () => {
|
|
127
|
-
const mockFetch = setupFetch({
|
|
128
|
-
json: () => Promise.resolve(sampleMatrixResponse)
|
|
129
|
-
});
|
|
130
|
-
const tool = new MatrixTool();
|
|
131
|
-
await tool.run({
|
|
132
|
-
coordinates: [
|
|
133
|
-
{ longitude: -122.42, latitude: 37.78 },
|
|
134
|
-
{ longitude: -122.45, latitude: 37.91 }
|
|
135
|
-
],
|
|
136
|
-
profile: 'driving',
|
|
137
|
-
bearings: '45,90;120,45'
|
|
138
|
-
});
|
|
139
|
-
const url = mockFetch.mock.calls[0][0];
|
|
140
|
-
expect(url).toContain('bearings=45%2C90%3B120%2C45');
|
|
141
|
-
});
|
|
142
|
-
it('properly includes destinations parameter when specified', async () => {
|
|
143
|
-
const mockFetch = setupFetch({
|
|
144
|
-
json: () => Promise.resolve(sampleMatrixResponse)
|
|
145
|
-
});
|
|
146
|
-
const tool = new MatrixTool();
|
|
147
|
-
await tool.run({
|
|
148
|
-
coordinates: [
|
|
149
|
-
{ longitude: -122.42, latitude: 37.78 },
|
|
150
|
-
{ longitude: -122.45, latitude: 37.91 },
|
|
151
|
-
{ longitude: -122.48, latitude: 37.73 }
|
|
152
|
-
],
|
|
153
|
-
profile: 'cycling',
|
|
154
|
-
destinations: '0;2'
|
|
155
|
-
});
|
|
156
|
-
const url = mockFetch.mock.calls[0][0];
|
|
157
|
-
expect(url).toContain('destinations=0%3B2');
|
|
158
|
-
});
|
|
159
|
-
it('properly includes sources parameter when specified', async () => {
|
|
160
|
-
const mockFetch = setupFetch({
|
|
161
|
-
json: () => Promise.resolve(sampleMatrixResponse)
|
|
162
|
-
});
|
|
163
|
-
const tool = new MatrixTool();
|
|
164
|
-
await tool.run({
|
|
165
|
-
coordinates: [
|
|
166
|
-
{ longitude: -122.42, latitude: 37.78 },
|
|
167
|
-
{ longitude: -122.45, latitude: 37.91 },
|
|
168
|
-
{ longitude: -122.48, latitude: 37.73 }
|
|
169
|
-
],
|
|
170
|
-
profile: 'walking',
|
|
171
|
-
sources: '1'
|
|
172
|
-
});
|
|
173
|
-
const url = mockFetch.mock.calls[0][0];
|
|
174
|
-
expect(url).toContain('sources=1');
|
|
175
|
-
});
|
|
176
|
-
it('handles all optional parameters together', async () => {
|
|
177
|
-
const mockFetch = setupFetch({
|
|
178
|
-
json: () => Promise.resolve(sampleMatrixWithDistanceResponse)
|
|
179
|
-
});
|
|
180
|
-
const tool = new MatrixTool();
|
|
181
|
-
const result = await tool.run({
|
|
182
|
-
coordinates: [
|
|
183
|
-
{ longitude: -122.42, latitude: 37.78 },
|
|
184
|
-
{ longitude: -122.45, latitude: 37.91 },
|
|
185
|
-
{ longitude: -122.48, latitude: 37.73 }
|
|
186
|
-
],
|
|
187
|
-
profile: 'driving',
|
|
188
|
-
annotations: 'distance,duration',
|
|
189
|
-
approaches: 'curb;unrestricted;curb',
|
|
190
|
-
bearings: '45,90;120,45;180,90',
|
|
191
|
-
destinations: '0;2',
|
|
192
|
-
sources: '1'
|
|
193
|
-
});
|
|
194
|
-
expect(result.is_error).toBe(false);
|
|
195
|
-
const url = mockFetch.mock.calls[0][0];
|
|
196
|
-
expect(url).toContain('annotations=distance%2Cduration');
|
|
197
|
-
expect(url).toContain('approaches=curb%3Bunrestricted%3Bcurb');
|
|
198
|
-
expect(url).toContain('bearings=45%2C90%3B120%2C45%3B180%2C90');
|
|
199
|
-
expect(url).toContain('destinations=0%3B2');
|
|
200
|
-
expect(url).toContain('sources=1');
|
|
201
|
-
});
|
|
202
|
-
it('handles fetch errors gracefully', async () => {
|
|
203
|
-
const mockFetch = setupFetch({
|
|
204
|
-
ok: false,
|
|
205
|
-
status: 404,
|
|
206
|
-
statusText: 'Not Found'
|
|
207
|
-
});
|
|
208
|
-
const tool = new MatrixTool();
|
|
209
|
-
const result = await tool.run({
|
|
210
|
-
coordinates: [
|
|
211
|
-
{ longitude: -122.42, latitude: 37.78 },
|
|
212
|
-
{ longitude: -122.45, latitude: 37.91 }
|
|
213
|
-
],
|
|
214
|
-
profile: 'walking'
|
|
215
|
-
});
|
|
216
|
-
expect(result.is_error).toBe(true);
|
|
217
|
-
expect(result.content[0]).toMatchObject({
|
|
218
|
-
type: 'text',
|
|
219
|
-
text: 'Internal error has occurred.'
|
|
220
|
-
});
|
|
221
|
-
assertHeadersSent(mockFetch);
|
|
222
|
-
});
|
|
223
|
-
it('validates driving-traffic profile coordinate limit', async () => {
|
|
224
|
-
const mockFetch = setupFetch();
|
|
225
|
-
const tool = new MatrixTool();
|
|
226
|
-
const coordinates = Array(11).fill({ longitude: -122.42, latitude: 37.78 });
|
|
227
|
-
const result = await tool.run({
|
|
228
|
-
coordinates,
|
|
229
|
-
profile: 'driving-traffic'
|
|
230
|
-
});
|
|
231
|
-
expect(result.is_error).toBe(true);
|
|
232
|
-
expect(mockFetch).not.toHaveBeenCalled();
|
|
233
|
-
// Test for specific error message by calling execute directly
|
|
234
|
-
await expect(async () => {
|
|
235
|
-
await tool['execute']({
|
|
236
|
-
coordinates,
|
|
237
|
-
profile: 'driving-traffic'
|
|
238
|
-
});
|
|
239
|
-
}).rejects.toThrow('The driving-traffic profile supports a maximum of 10 coordinate pairs.');
|
|
240
|
-
});
|
|
241
|
-
// Input validation tests
|
|
242
|
-
describe('input validation', () => {
|
|
243
|
-
let tool;
|
|
244
|
-
beforeEach(() => {
|
|
245
|
-
tool = new MatrixTool();
|
|
246
|
-
setupFetch();
|
|
247
|
-
});
|
|
248
|
-
it('validates coordinates - minimum count', async () => {
|
|
249
|
-
const result = await tool.run({
|
|
250
|
-
coordinates: [{ longitude: -122.42, latitude: 37.78 }],
|
|
251
|
-
profile: 'driving'
|
|
252
|
-
});
|
|
253
|
-
expect(result.is_error).toBe(true);
|
|
254
|
-
// Test direct error message using Zod validation from schema
|
|
255
|
-
await expect(async () => {
|
|
256
|
-
await tool['inputSchema'].parseAsync({
|
|
257
|
-
coordinates: [{ longitude: -122.42, latitude: 37.78 }],
|
|
258
|
-
profile: 'driving'
|
|
259
|
-
});
|
|
260
|
-
}).rejects.toThrow('At least two coordinate pairs are required.');
|
|
261
|
-
});
|
|
262
|
-
it('validates coordinates - maximum count for regular profiles', async () => {
|
|
263
|
-
const coordinates = Array(26).fill({
|
|
264
|
-
longitude: -122.42,
|
|
265
|
-
latitude: 37.78
|
|
266
|
-
});
|
|
267
|
-
const result = await tool.run({
|
|
268
|
-
coordinates,
|
|
269
|
-
profile: 'driving'
|
|
270
|
-
});
|
|
271
|
-
expect(result.is_error).toBe(true);
|
|
272
|
-
// Test direct error message using Zod validation from schema
|
|
273
|
-
await expect(async () => {
|
|
274
|
-
await tool['inputSchema'].parseAsync({
|
|
275
|
-
coordinates,
|
|
276
|
-
profile: 'driving'
|
|
277
|
-
});
|
|
278
|
-
}).rejects.toThrow('Up to 25 coordinate pairs are supported for most profiles (10 for driving-traffic).');
|
|
279
|
-
});
|
|
280
|
-
it('validates coordinate bounds', async () => {
|
|
281
|
-
const invalidLongitude = await tool.run({
|
|
282
|
-
coordinates: [
|
|
283
|
-
{ longitude: -190, latitude: 37.78 },
|
|
284
|
-
{ longitude: -122.45, latitude: 37.91 }
|
|
285
|
-
],
|
|
286
|
-
profile: 'driving'
|
|
287
|
-
});
|
|
288
|
-
expect(invalidLongitude.is_error).toBe(true);
|
|
289
|
-
// Test longitude bounds error message
|
|
290
|
-
await expect(async () => {
|
|
291
|
-
await tool['inputSchema'].parseAsync({
|
|
292
|
-
coordinates: [
|
|
293
|
-
{ longitude: -190, latitude: 37.78 },
|
|
294
|
-
{ longitude: -122.45, latitude: 37.91 }
|
|
295
|
-
],
|
|
296
|
-
profile: 'driving'
|
|
297
|
-
});
|
|
298
|
-
}).rejects.toThrow('Longitude must be between -180 and 180 degrees');
|
|
299
|
-
const invalidLatitude = await tool.run({
|
|
300
|
-
coordinates: [
|
|
301
|
-
{ longitude: -122.42, latitude: 37.78 },
|
|
302
|
-
{ longitude: -122.45, latitude: 95 }
|
|
303
|
-
],
|
|
304
|
-
profile: 'driving'
|
|
305
|
-
});
|
|
306
|
-
expect(invalidLatitude.is_error).toBe(true);
|
|
307
|
-
// Test latitude bounds error message
|
|
308
|
-
await expect(async () => {
|
|
309
|
-
await tool['inputSchema'].parseAsync({
|
|
310
|
-
coordinates: [
|
|
311
|
-
{ longitude: -122.42, latitude: 37.78 },
|
|
312
|
-
{ longitude: -122.45, latitude: 95 }
|
|
313
|
-
],
|
|
314
|
-
profile: 'driving'
|
|
315
|
-
});
|
|
316
|
-
}).rejects.toThrow('Latitude must be between -90 and 90 degrees');
|
|
317
|
-
});
|
|
318
|
-
it('validates approaches parameter length', async () => {
|
|
319
|
-
const result = await tool.run({
|
|
320
|
-
coordinates: [
|
|
321
|
-
{ longitude: -122.42, latitude: 37.78 },
|
|
322
|
-
{ longitude: -122.45, latitude: 37.91 },
|
|
323
|
-
{ longitude: -122.48, latitude: 37.73 }
|
|
324
|
-
],
|
|
325
|
-
profile: 'driving',
|
|
326
|
-
approaches: 'curb;unrestricted' // Only 2 for 3 coordinates
|
|
327
|
-
});
|
|
328
|
-
expect(result.is_error).toBe(true);
|
|
329
|
-
// Test direct error for approaches length mismatch
|
|
330
|
-
await expect(async () => {
|
|
331
|
-
await tool['execute']({
|
|
332
|
-
coordinates: [
|
|
333
|
-
{ longitude: -122.42, latitude: 37.78 },
|
|
334
|
-
{ longitude: -122.45, latitude: 37.91 },
|
|
335
|
-
{ longitude: -122.48, latitude: 37.73 }
|
|
336
|
-
],
|
|
337
|
-
profile: 'driving',
|
|
338
|
-
approaches: 'curb;unrestricted'
|
|
339
|
-
});
|
|
340
|
-
}).rejects.toThrow('When provided, the number of approaches (including empty/skipped) must match the number of coordinates.');
|
|
341
|
-
});
|
|
342
|
-
it('validates approaches parameter values', async () => {
|
|
343
|
-
const result = await tool.run({
|
|
344
|
-
coordinates: [
|
|
345
|
-
{ longitude: -122.42, latitude: 37.78 },
|
|
346
|
-
{ longitude: -122.45, latitude: 37.91 }
|
|
347
|
-
],
|
|
348
|
-
profile: 'driving',
|
|
349
|
-
approaches: 'curb;invalid' // 'invalid' is not allowed
|
|
350
|
-
});
|
|
351
|
-
expect(result.is_error).toBe(true);
|
|
352
|
-
// Test direct error for invalid approach value
|
|
353
|
-
await expect(async () => {
|
|
354
|
-
await tool['execute']({
|
|
355
|
-
coordinates: [
|
|
356
|
-
{ longitude: -122.42, latitude: 37.78 },
|
|
357
|
-
{ longitude: -122.45, latitude: 37.91 }
|
|
358
|
-
],
|
|
359
|
-
profile: 'driving',
|
|
360
|
-
approaches: 'curb;invalid'
|
|
361
|
-
});
|
|
362
|
-
}).rejects.toThrow('Approaches parameter contains invalid values. Each value must be either "curb" or "unrestricted".');
|
|
363
|
-
});
|
|
364
|
-
it('validates bearings parameter length', async () => {
|
|
365
|
-
const result = await tool.run({
|
|
366
|
-
coordinates: [
|
|
367
|
-
{ longitude: -122.42, latitude: 37.78 },
|
|
368
|
-
{ longitude: -122.45, latitude: 37.91 },
|
|
369
|
-
{ longitude: -122.48, latitude: 37.73 }
|
|
370
|
-
],
|
|
371
|
-
profile: 'driving',
|
|
372
|
-
bearings: '45,90;120,45' // Only 2 for 3 coordinates
|
|
373
|
-
});
|
|
374
|
-
expect(result.is_error).toBe(true);
|
|
375
|
-
// Test direct error for bearings length mismatch
|
|
376
|
-
await expect(async () => {
|
|
377
|
-
await tool['execute']({
|
|
378
|
-
coordinates: [
|
|
379
|
-
{ longitude: -122.42, latitude: 37.78 },
|
|
380
|
-
{ longitude: -122.45, latitude: 37.91 },
|
|
381
|
-
{ longitude: -122.48, latitude: 37.73 }
|
|
382
|
-
],
|
|
383
|
-
profile: 'driving',
|
|
384
|
-
bearings: '45,90;120,45'
|
|
385
|
-
});
|
|
386
|
-
}).rejects.toThrow('When provided, the number of bearings (including empty/skipped) must match the number of coordinates.');
|
|
387
|
-
});
|
|
388
|
-
it('validates bearings parameter format', async () => {
|
|
389
|
-
const result = await tool.run({
|
|
390
|
-
coordinates: [
|
|
391
|
-
{ longitude: -122.42, latitude: 37.78 },
|
|
392
|
-
{ longitude: -122.45, latitude: 37.91 }
|
|
393
|
-
],
|
|
394
|
-
profile: 'driving',
|
|
395
|
-
bearings: '45,90;invalid'
|
|
396
|
-
});
|
|
397
|
-
expect(result.is_error).toBe(true);
|
|
398
|
-
// Test direct error for invalid bearing format
|
|
399
|
-
await expect(async () => {
|
|
400
|
-
await tool['execute']({
|
|
401
|
-
coordinates: [
|
|
402
|
-
{ longitude: -122.42, latitude: 37.78 },
|
|
403
|
-
{ longitude: -122.45, latitude: 37.91 }
|
|
404
|
-
],
|
|
405
|
-
profile: 'driving',
|
|
406
|
-
bearings: '45,90;invalid'
|
|
407
|
-
});
|
|
408
|
-
}).rejects.toThrow('Invalid bearings format at index 1');
|
|
409
|
-
});
|
|
410
|
-
it('validates bearings parameter angle range', async () => {
|
|
411
|
-
const result = await tool.run({
|
|
412
|
-
coordinates: [
|
|
413
|
-
{ longitude: -122.42, latitude: 37.78 },
|
|
414
|
-
{ longitude: -122.45, latitude: 37.91 }
|
|
415
|
-
],
|
|
416
|
-
profile: 'driving',
|
|
417
|
-
bearings: '400,90;120,45' // 400 is > 360
|
|
418
|
-
});
|
|
419
|
-
expect(result.is_error).toBe(true);
|
|
420
|
-
// Test direct error for invalid bearing angle
|
|
421
|
-
await expect(async () => {
|
|
422
|
-
await tool['execute']({
|
|
423
|
-
coordinates: [
|
|
424
|
-
{ longitude: -122.42, latitude: 37.78 },
|
|
425
|
-
{ longitude: -122.45, latitude: 37.91 }
|
|
426
|
-
],
|
|
427
|
-
profile: 'driving',
|
|
428
|
-
bearings: '400,90;120,45'
|
|
429
|
-
});
|
|
430
|
-
}).rejects.toThrow('Invalid bearing angle at index 0');
|
|
431
|
-
});
|
|
432
|
-
it('validates bearings parameter degrees range', async () => {
|
|
433
|
-
const result = await tool.run({
|
|
434
|
-
coordinates: [
|
|
435
|
-
{ longitude: -122.42, latitude: 37.78 },
|
|
436
|
-
{ longitude: -122.45, latitude: 37.91 }
|
|
437
|
-
],
|
|
438
|
-
profile: 'driving',
|
|
439
|
-
bearings: '45,200;120,45' // 200 is > 180
|
|
440
|
-
});
|
|
441
|
-
expect(result.is_error).toBe(true);
|
|
442
|
-
// Test direct error for invalid bearing degrees
|
|
443
|
-
await expect(async () => {
|
|
444
|
-
await tool['execute']({
|
|
445
|
-
coordinates: [
|
|
446
|
-
{ longitude: -122.42, latitude: 37.78 },
|
|
447
|
-
{ longitude: -122.45, latitude: 37.91 }
|
|
448
|
-
],
|
|
449
|
-
profile: 'driving',
|
|
450
|
-
bearings: '45,200;120,45'
|
|
451
|
-
});
|
|
452
|
-
}).rejects.toThrow('Invalid bearing degrees at index 0');
|
|
453
|
-
});
|
|
454
|
-
it('validates sources parameter indices', async () => {
|
|
455
|
-
const result = await tool.run({
|
|
456
|
-
coordinates: [
|
|
457
|
-
{ longitude: -122.42, latitude: 37.78 },
|
|
458
|
-
{ longitude: -122.45, latitude: 37.91 }
|
|
459
|
-
],
|
|
460
|
-
profile: 'driving',
|
|
461
|
-
sources: '0;2' // 2 is out of bounds
|
|
462
|
-
});
|
|
463
|
-
expect(result.is_error).toBe(true);
|
|
464
|
-
// Test direct error message for invalid sources indices
|
|
465
|
-
await expect(async () => {
|
|
466
|
-
await tool['execute']({
|
|
467
|
-
coordinates: [
|
|
468
|
-
{ longitude: -122.42, latitude: 37.78 },
|
|
469
|
-
{ longitude: -122.45, latitude: 37.91 }
|
|
470
|
-
],
|
|
471
|
-
profile: 'driving',
|
|
472
|
-
sources: '0;2'
|
|
473
|
-
});
|
|
474
|
-
}).rejects.toThrow('Sources parameter contains invalid indices. All indices must be between 0 and 1.');
|
|
475
|
-
});
|
|
476
|
-
it('validates destinations parameter indices', async () => {
|
|
477
|
-
const result = await tool.run({
|
|
478
|
-
coordinates: [
|
|
479
|
-
{ longitude: -122.42, latitude: 37.78 },
|
|
480
|
-
{ longitude: -122.45, latitude: 37.91 }
|
|
481
|
-
],
|
|
482
|
-
profile: 'driving',
|
|
483
|
-
destinations: '3' // 3 is out of bounds
|
|
484
|
-
});
|
|
485
|
-
expect(result.is_error).toBe(true);
|
|
486
|
-
// Test direct error message for invalid destinations indices
|
|
487
|
-
await expect(async () => {
|
|
488
|
-
await tool['execute']({
|
|
489
|
-
coordinates: [
|
|
490
|
-
{ longitude: -122.42, latitude: 37.78 },
|
|
491
|
-
{ longitude: -122.45, latitude: 37.91 }
|
|
492
|
-
],
|
|
493
|
-
profile: 'driving',
|
|
494
|
-
destinations: '3'
|
|
495
|
-
});
|
|
496
|
-
}).rejects.toThrow('Destinations parameter contains invalid indices. All indices must be between 0 and 1.');
|
|
497
|
-
});
|
|
498
|
-
it('validates destinations parameter index negative', async () => {
|
|
499
|
-
const result = await tool.run({
|
|
500
|
-
coordinates: [
|
|
501
|
-
{ longitude: -122.42, latitude: 37.78 },
|
|
502
|
-
{ longitude: -122.45, latitude: 37.91 }
|
|
503
|
-
],
|
|
504
|
-
profile: 'driving',
|
|
505
|
-
destinations: '-1'
|
|
506
|
-
});
|
|
507
|
-
expect(result.is_error).toBe(true);
|
|
508
|
-
// Test direct error message for invalid destinations indices
|
|
509
|
-
await expect(async () => {
|
|
510
|
-
await tool['execute']({
|
|
511
|
-
coordinates: [
|
|
512
|
-
{ longitude: -122.42, latitude: 37.78 },
|
|
513
|
-
{ longitude: -122.45, latitude: 37.91 }
|
|
514
|
-
],
|
|
515
|
-
profile: 'driving',
|
|
516
|
-
destinations: '-1'
|
|
517
|
-
});
|
|
518
|
-
}).rejects.toThrow('Destinations parameter contains invalid indices. All indices must be between 0 and 1.');
|
|
519
|
-
});
|
|
520
|
-
it('accepts valid "all" value for sources', async () => {
|
|
521
|
-
const mockFetch = setupFetch({
|
|
522
|
-
json: () => Promise.resolve(sampleMatrixResponse)
|
|
523
|
-
});
|
|
524
|
-
await tool.run({
|
|
525
|
-
coordinates: [
|
|
526
|
-
{ longitude: -122.42, latitude: 37.78 },
|
|
527
|
-
{ longitude: -122.45, latitude: 37.91 }
|
|
528
|
-
],
|
|
529
|
-
profile: 'driving',
|
|
530
|
-
sources: 'all'
|
|
531
|
-
});
|
|
532
|
-
const url = mockFetch.mock.calls[0][0];
|
|
533
|
-
expect(url).toContain('sources=all');
|
|
534
|
-
});
|
|
535
|
-
it('accepts valid "all" value for destinations', async () => {
|
|
536
|
-
const mockFetch = setupFetch({
|
|
537
|
-
json: () => Promise.resolve(sampleMatrixResponse)
|
|
538
|
-
});
|
|
539
|
-
await tool.run({
|
|
540
|
-
coordinates: [
|
|
541
|
-
{ longitude: -122.42, latitude: 37.78 },
|
|
542
|
-
{ longitude: -122.45, latitude: 37.91 }
|
|
543
|
-
],
|
|
544
|
-
profile: 'driving',
|
|
545
|
-
destinations: 'all'
|
|
546
|
-
});
|
|
547
|
-
const url = mockFetch.mock.calls[0][0];
|
|
548
|
-
expect(url).toContain('destinations=all');
|
|
549
|
-
});
|
|
550
|
-
});
|
|
551
|
-
// Parameter edge cases
|
|
552
|
-
describe('parameter edge cases', () => {
|
|
553
|
-
let tool;
|
|
554
|
-
beforeEach(() => {
|
|
555
|
-
tool = new MatrixTool();
|
|
556
|
-
});
|
|
557
|
-
it('accepts approaches with skipped values', async () => {
|
|
558
|
-
const mockFetch = setupFetch({
|
|
559
|
-
json: () => Promise.resolve(sampleMatrixResponse)
|
|
560
|
-
});
|
|
561
|
-
const result = await tool.run({
|
|
562
|
-
coordinates: [
|
|
563
|
-
{ longitude: -122.42, latitude: 37.78 },
|
|
564
|
-
{ longitude: -122.46, latitude: 37.9 },
|
|
565
|
-
{ longitude: -122.48, latitude: 37.73 }
|
|
566
|
-
],
|
|
567
|
-
profile: 'driving',
|
|
568
|
-
approaches: 'curb;;unrestricted'
|
|
569
|
-
});
|
|
570
|
-
expect(result.is_error).toBe(false);
|
|
571
|
-
const url = mockFetch.mock.calls[0][0];
|
|
572
|
-
expect(url).toContain('approaches=curb%3B%3Bunrestricted');
|
|
573
|
-
});
|
|
574
|
-
it('accepts bearings with skipped values', async () => {
|
|
575
|
-
const mockFetch = setupFetch({
|
|
576
|
-
json: () => Promise.resolve(sampleMatrixResponse)
|
|
577
|
-
});
|
|
578
|
-
const result = await tool.run({
|
|
579
|
-
coordinates: [
|
|
580
|
-
{ longitude: -122.42, latitude: 37.78 },
|
|
581
|
-
{ longitude: -122.46, latitude: 37.9 },
|
|
582
|
-
{ longitude: -122.45, latitude: 37.91 }
|
|
583
|
-
],
|
|
584
|
-
profile: 'driving',
|
|
585
|
-
bearings: '45,90;;120,45'
|
|
586
|
-
});
|
|
587
|
-
expect(result.is_error).toBe(false);
|
|
588
|
-
const url = mockFetch.mock.calls[0][0];
|
|
589
|
-
expect(url).toContain('bearings=45%2C90%3B%3B120%2C45');
|
|
590
|
-
});
|
|
591
|
-
it('validates empty values correctly in approaches', async () => {
|
|
592
|
-
const mockFetch = setupFetch({
|
|
593
|
-
json: () => Promise.resolve(sampleMatrixResponse)
|
|
594
|
-
});
|
|
595
|
-
const resultWithSuccess1 = await tool.run({
|
|
596
|
-
coordinates: [
|
|
597
|
-
{ longitude: -122.42, latitude: 37.78 },
|
|
598
|
-
{ longitude: -122.45, latitude: 37.91 },
|
|
599
|
-
{ longitude: -122.48, latitude: 37.73 }
|
|
600
|
-
],
|
|
601
|
-
profile: 'driving',
|
|
602
|
-
approaches: 'curb;;unrestricted'
|
|
603
|
-
});
|
|
604
|
-
expect(resultWithSuccess1.is_error).toBe(false);
|
|
605
|
-
const resultWithSuccess2 = await tool.run({
|
|
606
|
-
coordinates: [
|
|
607
|
-
{ longitude: -122.42, latitude: 37.78 },
|
|
608
|
-
{ longitude: -122.45, latitude: 37.91 }
|
|
609
|
-
],
|
|
610
|
-
profile: 'driving',
|
|
611
|
-
approaches: 'curb;'
|
|
612
|
-
});
|
|
613
|
-
expect(resultWithSuccess2.is_error).toBe(false);
|
|
614
|
-
});
|
|
615
|
-
it('rejects sources and destinations with unused coordinates', async () => {
|
|
616
|
-
const mockFetch = setupFetch({
|
|
617
|
-
json: () => Promise.resolve(sampleMatrixResponse)
|
|
618
|
-
});
|
|
619
|
-
const result = await tool.run({
|
|
620
|
-
coordinates: [
|
|
621
|
-
{ longitude: -122.42, latitude: 37.78 },
|
|
622
|
-
{ longitude: -122.45, latitude: 37.91 },
|
|
623
|
-
{ longitude: -122.48, latitude: 37.73 }
|
|
624
|
-
],
|
|
625
|
-
profile: 'driving',
|
|
626
|
-
sources: '1',
|
|
627
|
-
destinations: '2'
|
|
628
|
-
});
|
|
629
|
-
expect(result.is_error).toBe(true);
|
|
630
|
-
expect(mockFetch).not.toHaveBeenCalled();
|
|
631
|
-
// Test direct error message for unused coordinates
|
|
632
|
-
await expect(async () => {
|
|
633
|
-
await tool['execute']({
|
|
634
|
-
coordinates: [
|
|
635
|
-
{ longitude: -122.42, latitude: 37.78 },
|
|
636
|
-
{ longitude: -122.45, latitude: 37.91 },
|
|
637
|
-
{ longitude: -122.48, latitude: 37.73 }
|
|
638
|
-
],
|
|
639
|
-
profile: 'driving',
|
|
640
|
-
sources: '1',
|
|
641
|
-
destinations: '2'
|
|
642
|
-
});
|
|
643
|
-
}).rejects.toThrow('When specifying both sources and destinations, all coordinates must be used as either a source or destination.');
|
|
644
|
-
});
|
|
645
|
-
it('accepts sources and destinations with single indices when all coordinates are used', async () => {
|
|
646
|
-
const mockFetch = setupFetch({
|
|
647
|
-
json: () => Promise.resolve(sampleMatrixResponse)
|
|
648
|
-
});
|
|
649
|
-
await tool.run({
|
|
650
|
-
coordinates: [
|
|
651
|
-
{ longitude: -122.42, latitude: 37.78 },
|
|
652
|
-
{ longitude: -122.45, latitude: 37.91 }
|
|
653
|
-
],
|
|
654
|
-
profile: 'driving',
|
|
655
|
-
sources: '0',
|
|
656
|
-
destinations: '1'
|
|
657
|
-
});
|
|
658
|
-
const url = mockFetch.mock.calls[0][0];
|
|
659
|
-
expect(url).toContain('sources=0');
|
|
660
|
-
expect(url).toContain('destinations=1');
|
|
661
|
-
});
|
|
662
|
-
it('accepts both annotations orders', async () => {
|
|
663
|
-
const mockFetch1 = setupFetch({
|
|
664
|
-
json: () => Promise.resolve(sampleMatrixWithDistanceResponse)
|
|
665
|
-
});
|
|
666
|
-
await tool.run({
|
|
667
|
-
coordinates: [
|
|
668
|
-
{ longitude: -122.42, latitude: 37.78 },
|
|
669
|
-
{ longitude: -122.45, latitude: 37.91 }
|
|
670
|
-
],
|
|
671
|
-
profile: 'driving',
|
|
672
|
-
annotations: 'duration,distance'
|
|
673
|
-
});
|
|
674
|
-
const url1 = mockFetch1.mock.calls[0][0];
|
|
675
|
-
expect(url1).toContain('annotations=duration%2Cdistance');
|
|
676
|
-
const mockFetch2 = setupFetch({
|
|
677
|
-
json: () => Promise.resolve(sampleMatrixWithDistanceResponse)
|
|
678
|
-
});
|
|
679
|
-
await tool.run({
|
|
680
|
-
coordinates: [
|
|
681
|
-
{ longitude: -122.42, latitude: 37.78 },
|
|
682
|
-
{ longitude: -122.45, latitude: 37.91 }
|
|
683
|
-
],
|
|
684
|
-
profile: 'driving',
|
|
685
|
-
annotations: 'distance,duration'
|
|
686
|
-
});
|
|
687
|
-
const url2 = mockFetch2.mock.calls[0][0];
|
|
688
|
-
expect(url2).toContain('annotations=distance%2Cduration');
|
|
689
|
-
});
|
|
690
|
-
});
|
|
691
|
-
// Large input tests
|
|
692
|
-
describe('large input', () => {
|
|
693
|
-
let tool;
|
|
694
|
-
beforeEach(() => {
|
|
695
|
-
tool = new MatrixTool();
|
|
696
|
-
});
|
|
697
|
-
it('accepts 25 coordinates for non-driving-traffic profiles', async () => {
|
|
698
|
-
const mockFetch = setupFetch({
|
|
699
|
-
json: () => Promise.resolve(sampleMatrixResponse)
|
|
700
|
-
});
|
|
701
|
-
const coordinates = Array.from({ length: 25 }, (_, i) => ({
|
|
702
|
-
longitude: -122.42 + i * 0.01,
|
|
703
|
-
latitude: 37.78 + i * 0.01
|
|
704
|
-
}));
|
|
705
|
-
const result = await tool.run({
|
|
706
|
-
coordinates,
|
|
707
|
-
profile: 'driving'
|
|
708
|
-
});
|
|
709
|
-
expect(result.is_error).toBe(false);
|
|
710
|
-
expect(mockFetch).toHaveBeenCalled();
|
|
711
|
-
});
|
|
712
|
-
it('accepts 10 coordinates for driving-traffic profile', async () => {
|
|
713
|
-
const mockFetch = setupFetch({
|
|
714
|
-
json: () => Promise.resolve(sampleMatrixResponse)
|
|
715
|
-
});
|
|
716
|
-
const coordinates = Array.from({ length: 10 }, (_, i) => ({
|
|
717
|
-
longitude: -122.42 + i * 0.01,
|
|
718
|
-
latitude: 37.78 + i * 0.01
|
|
719
|
-
}));
|
|
720
|
-
const result = await tool.run({
|
|
721
|
-
coordinates,
|
|
722
|
-
profile: 'driving-traffic'
|
|
723
|
-
});
|
|
724
|
-
expect(result.is_error).toBe(false);
|
|
725
|
-
expect(mockFetch).toHaveBeenCalled();
|
|
726
|
-
});
|
|
727
|
-
it('rejects 11 coordinates for driving-traffic profile', async () => {
|
|
728
|
-
const mockFetch = setupFetch();
|
|
729
|
-
const coordinates = Array.from({ length: 11 }, (_, i) => ({
|
|
730
|
-
longitude: -122.42 + i * 0.01,
|
|
731
|
-
latitude: 37.78 + i * 0.01
|
|
732
|
-
}));
|
|
733
|
-
const result = await tool.run({
|
|
734
|
-
coordinates,
|
|
735
|
-
profile: 'driving-traffic'
|
|
736
|
-
});
|
|
737
|
-
expect(result.is_error).toBe(true);
|
|
738
|
-
expect(mockFetch).not.toHaveBeenCalled();
|
|
739
|
-
// Test direct error message for exceeding coordinate limit
|
|
740
|
-
await expect(async () => {
|
|
741
|
-
await tool['execute']({
|
|
742
|
-
coordinates,
|
|
743
|
-
profile: 'driving-traffic'
|
|
744
|
-
});
|
|
745
|
-
}).rejects.toThrow('The driving-traffic profile supports a maximum of 10 coordinate pairs.');
|
|
746
|
-
});
|
|
747
|
-
});
|
|
748
|
-
// Test for different profiles
|
|
749
|
-
describe('profiles', () => {
|
|
750
|
-
let tool;
|
|
751
|
-
beforeEach(() => {
|
|
752
|
-
tool = new MatrixTool();
|
|
753
|
-
});
|
|
754
|
-
it('works with driving-traffic profile', async () => {
|
|
755
|
-
const mockFetch = setupFetch({
|
|
756
|
-
json: () => Promise.resolve(sampleMatrixResponse)
|
|
757
|
-
});
|
|
758
|
-
const result = await tool.run({
|
|
759
|
-
coordinates: [
|
|
760
|
-
{ longitude: -122.42, latitude: 37.78 },
|
|
761
|
-
{ longitude: -122.45, latitude: 37.91 }
|
|
762
|
-
],
|
|
763
|
-
profile: 'driving-traffic'
|
|
764
|
-
});
|
|
765
|
-
expect(result.is_error).toBe(false);
|
|
766
|
-
const url = mockFetch.mock.calls[0][0];
|
|
767
|
-
expect(url).toContain('directions-matrix/v1/mapbox/driving-traffic');
|
|
768
|
-
});
|
|
769
|
-
it('works with driving profile', async () => {
|
|
770
|
-
const mockFetch = setupFetch({
|
|
771
|
-
json: () => Promise.resolve(sampleMatrixResponse)
|
|
772
|
-
});
|
|
773
|
-
const result = await tool.run({
|
|
774
|
-
coordinates: [
|
|
775
|
-
{ longitude: -122.42, latitude: 37.78 },
|
|
776
|
-
{ longitude: -122.45, latitude: 37.91 }
|
|
777
|
-
],
|
|
778
|
-
profile: 'driving'
|
|
779
|
-
});
|
|
780
|
-
expect(result.is_error).toBe(false);
|
|
781
|
-
const url = mockFetch.mock.calls[0][0];
|
|
782
|
-
expect(url).toContain('directions-matrix/v1/mapbox/driving');
|
|
783
|
-
});
|
|
784
|
-
it('works with walking profile', async () => {
|
|
785
|
-
const mockFetch = setupFetch({
|
|
786
|
-
json: () => Promise.resolve(sampleMatrixResponse)
|
|
787
|
-
});
|
|
788
|
-
const result = await tool.run({
|
|
789
|
-
coordinates: [
|
|
790
|
-
{ longitude: -122.42, latitude: 37.78 },
|
|
791
|
-
{ longitude: -122.45, latitude: 37.91 }
|
|
792
|
-
],
|
|
793
|
-
profile: 'walking'
|
|
794
|
-
});
|
|
795
|
-
expect(result.is_error).toBe(false);
|
|
796
|
-
const url = mockFetch.mock.calls[0][0];
|
|
797
|
-
expect(url).toContain('directions-matrix/v1/mapbox/walking');
|
|
798
|
-
});
|
|
799
|
-
it('works with cycling profile', async () => {
|
|
800
|
-
const mockFetch = setupFetch({
|
|
801
|
-
json: () => Promise.resolve(sampleMatrixResponse)
|
|
802
|
-
});
|
|
803
|
-
const result = await tool.run({
|
|
804
|
-
coordinates: [
|
|
805
|
-
{ longitude: -122.42, latitude: 37.78 },
|
|
806
|
-
{ longitude: -122.45, latitude: 37.91 }
|
|
807
|
-
],
|
|
808
|
-
profile: 'cycling'
|
|
809
|
-
});
|
|
810
|
-
expect(result.is_error).toBe(false);
|
|
811
|
-
const url = mockFetch.mock.calls[0][0];
|
|
812
|
-
expect(url).toContain('directions-matrix/v1/mapbox/cycling');
|
|
813
|
-
});
|
|
814
|
-
});
|
|
815
|
-
});
|
|
816
|
-
//# sourceMappingURL=MatrixTool.test.js.map
|