|
| 1 | +import { TilequeryTool } from './TilequeryTool.js'; |
| 2 | +import { TilequeryInput } from './TilequeryTool.schema.js'; |
| 3 | + |
| 4 | +describe('TilequeryTool', () => { |
| 5 | + let tool: TilequeryTool; |
| 6 | + |
| 7 | + beforeEach(() => { |
| 8 | + tool = new TilequeryTool(); |
| 9 | + }); |
| 10 | + |
| 11 | + describe('constructor', () => { |
| 12 | + it('should initialize with correct name and description', () => { |
| 13 | + expect(tool.name).toBe('tilequery_tool'); |
| 14 | + expect(tool.description).toBe( |
| 15 | + 'Query vector and raster data from Mapbox tilesets at geographic coordinates' |
| 16 | + ); |
| 17 | + }); |
| 18 | + }); |
| 19 | + |
| 20 | + describe('schema validation', () => { |
| 21 | + it('should validate minimal valid input', () => { |
| 22 | + const input = { |
| 23 | + longitude: -122.4194, |
| 24 | + latitude: 37.7749 |
| 25 | + }; |
| 26 | + |
| 27 | + const result = tool.inputSchema.safeParse(input); |
| 28 | + expect(result.success).toBe(true); |
| 29 | + if (result.success) { |
| 30 | + expect(result.data.tilesetId).toBe('mapbox.mapbox-streets-v8'); |
| 31 | + expect(result.data.radius).toBe(0); |
| 32 | + expect(result.data.limit).toBe(5); |
| 33 | + expect(result.data.dedupe).toBe(true); |
| 34 | + } |
| 35 | + }); |
| 36 | + |
| 37 | + it('should validate complete input with all optional parameters', () => { |
| 38 | + const input: TilequeryInput = { |
| 39 | + tilesetId: 'custom.tileset', |
| 40 | + longitude: -122.4194, |
| 41 | + latitude: 37.7749, |
| 42 | + radius: 100, |
| 43 | + limit: 10, |
| 44 | + dedupe: false, |
| 45 | + geometry: 'polygon', |
| 46 | + layers: ['buildings', 'roads'], |
| 47 | + bands: ['band1', 'band2'] |
| 48 | + }; |
| 49 | + |
| 50 | + const result = tool.inputSchema.safeParse(input); |
| 51 | + expect(result.success).toBe(true); |
| 52 | + }); |
| 53 | + |
| 54 | + it('should reject invalid longitude', () => { |
| 55 | + const input = { |
| 56 | + longitude: 181, // Invalid: > 180 |
| 57 | + latitude: 37.7749 |
| 58 | + }; |
| 59 | + |
| 60 | + const result = tool.inputSchema.safeParse(input); |
| 61 | + expect(result.success).toBe(false); |
| 62 | + }); |
| 63 | + |
| 64 | + it('should reject invalid latitude', () => { |
| 65 | + const input = { |
| 66 | + longitude: -122.4194, |
| 67 | + latitude: 91 // Invalid: > 90 |
| 68 | + }; |
| 69 | + |
| 70 | + const result = tool.inputSchema.safeParse(input); |
| 71 | + expect(result.success).toBe(false); |
| 72 | + }); |
| 73 | + |
| 74 | + it('should reject limit outside valid range', () => { |
| 75 | + const input = { |
| 76 | + longitude: -122.4194, |
| 77 | + latitude: 37.7749, |
| 78 | + limit: 51 // Invalid: > 50 |
| 79 | + }; |
| 80 | + |
| 81 | + const result = tool.inputSchema.safeParse(input); |
| 82 | + expect(result.success).toBe(false); |
| 83 | + }); |
| 84 | + |
| 85 | + it('should reject invalid geometry type', () => { |
| 86 | + const input = { |
| 87 | + longitude: -122.4194, |
| 88 | + latitude: 37.7749, |
| 89 | + geometry: 'invalid' as 'polygon' |
| 90 | + }; |
| 91 | + |
| 92 | + const result = tool.inputSchema.safeParse(input); |
| 93 | + expect(result.success).toBe(false); |
| 94 | + }); |
| 95 | + }); |
| 96 | +}); |
0 commit comments