|
1 | 1 | // Copyright (c) Mapbox, Inc. |
2 | 2 | // Licensed under the MIT License. |
3 | 3 |
|
4 | | -import { describe, it, expect, beforeEach } from 'vitest'; |
| 4 | +import { describe, it, expect, beforeAll, beforeEach } from 'vitest'; |
5 | 5 | import { TilequeryTool } from '../../../src/tools/tilequery-tool/TilequeryTool.js'; |
6 | 6 | import { TilequeryInput } from '../../../src/tools/tilequery-tool/TilequeryTool.input.schema.js'; |
7 | 7 | import { setupHttpRequest } from '../../utils/httpPipelineUtils.js'; |
8 | 8 |
|
| 9 | +beforeAll(() => { |
| 10 | + process.env.MAPBOX_ACCESS_TOKEN = |
| 11 | + 'eyJhbGciOiJIUzI1NiJ9.eyJ1IjoidGVzdC11c2VyIiwiYSI6InRlc3QtYXBpIn0.signature'; |
| 12 | +}); |
| 13 | + |
9 | 14 | describe('TilequeryTool', () => { |
10 | 15 | let tool: TilequeryTool; |
11 | 16 |
|
@@ -99,4 +104,23 @@ describe('TilequeryTool', () => { |
99 | 104 | expect(result.success).toBe(false); |
100 | 105 | }); |
101 | 106 | }); |
| 107 | + |
| 108 | + describe('execute', () => { |
| 109 | + it('returns error with validation details when API response does not match schema', async () => { |
| 110 | + const { httpRequest } = setupHttpRequest({ |
| 111 | + ok: true, |
| 112 | + json: async () => ({ unexpected: 'format' }) |
| 113 | + }); |
| 114 | + |
| 115 | + const result = await new TilequeryTool({ httpRequest }).run({ |
| 116 | + longitude: -122.4194, |
| 117 | + latitude: 37.7749 |
| 118 | + }); |
| 119 | + |
| 120 | + expect(result.isError).toBe(true); |
| 121 | + const text = (result.content[0] as { type: string; text: string }).text; |
| 122 | + expect(text).toMatch(/Unexpected API response format from Mapbox API:/); |
| 123 | + expect(text).toContain('"code"'); |
| 124 | + }); |
| 125 | + }); |
102 | 126 | }); |
0 commit comments