Skip to content

Commit 5c16a08

Browse files
committed
test: add validation error response tests for TilequeryTool and RetrieveStyleTool
1 parent da324a4 commit 5c16a08

2 files changed

Lines changed: 41 additions & 1 deletion

File tree

test/tools/retrieve-style-tool/RetrieveStyleTool.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,22 @@ describe('RetrieveStyleTool', () => {
101101
assertHeadersSent(mockHttpRequest);
102102
});
103103

104+
it('returns error with validation details when API response does not match schema', async () => {
105+
const { httpRequest } = setupHttpRequest({
106+
ok: true,
107+
json: async () => ({ unexpected: 'format' })
108+
});
109+
110+
const result = await new RetrieveStyleTool({ httpRequest }).run({
111+
styleId: 'cmojrmkc9002t01ry96yi6h48'
112+
});
113+
114+
expect(result.isError).toBe(true);
115+
const text = (result.content[0] as { type: string; text: string }).text;
116+
expect(text).toMatch(/Unexpected API response format from Mapbox API:/);
117+
expect(text).toContain('"code"');
118+
});
119+
104120
it('handles styles with null terrain and other nullable fields', async () => {
105121
// Real-world API response with null values for optional fields
106122
const styleData = {

test/tools/tilequery-tool/TilequeryTool.test.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
// Copyright (c) Mapbox, Inc.
22
// Licensed under the MIT License.
33

4-
import { describe, it, expect, beforeEach } from 'vitest';
4+
import { describe, it, expect, beforeAll, beforeEach } from 'vitest';
55
import { TilequeryTool } from '../../../src/tools/tilequery-tool/TilequeryTool.js';
66
import { TilequeryInput } from '../../../src/tools/tilequery-tool/TilequeryTool.input.schema.js';
77
import { setupHttpRequest } from '../../utils/httpPipelineUtils.js';
88

9+
beforeAll(() => {
10+
process.env.MAPBOX_ACCESS_TOKEN =
11+
'eyJhbGciOiJIUzI1NiJ9.eyJ1IjoidGVzdC11c2VyIiwiYSI6InRlc3QtYXBpIn0.signature';
12+
});
13+
914
describe('TilequeryTool', () => {
1015
let tool: TilequeryTool;
1116

@@ -99,4 +104,23 @@ describe('TilequeryTool', () => {
99104
expect(result.success).toBe(false);
100105
});
101106
});
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+
});
102126
});

0 commit comments

Comments
 (0)