Add MCP server edge-case tests for find_nodes and Zod validation
Covers a few gaps in the existing MCP test suite: - find_nodes filtering by type (wasn't exercised at all) - create_shape with an invalid type enum (Zod enforcement) - create_shape with a missing required param (Zod enforcement)
This commit is contained in:
parent
3e178edb50
commit
274c9f7d61
|
|
@ -217,4 +217,48 @@ describe('MCP server', () => {
|
|||
const container2 = tree2.children.find((c) => c.id === frame.id)
|
||||
expect(container2!.children ?? []).toHaveLength(0)
|
||||
})
|
||||
|
||||
test('find_nodes filters by type', async () => {
|
||||
await client.callTool({ name: 'new_document', arguments: {} })
|
||||
await client.callTool({
|
||||
name: 'create_shape',
|
||||
arguments: { type: 'FRAME', x: 0, y: 0, width: 100, height: 100, name: 'F1' }
|
||||
})
|
||||
await client.callTool({
|
||||
name: 'create_shape',
|
||||
arguments: { type: 'RECTANGLE', x: 0, y: 0, width: 50, height: 50, name: 'R1' }
|
||||
})
|
||||
await client.callTool({
|
||||
name: 'create_shape',
|
||||
arguments: { type: 'FRAME', x: 0, y: 0, width: 100, height: 100, name: 'F2' }
|
||||
})
|
||||
|
||||
const result = await client.callTool({ name: 'find_nodes', arguments: { type: 'FRAME' } })
|
||||
const data = parseResult(result) as { count: number }
|
||||
expect(data.count).toBe(2)
|
||||
})
|
||||
|
||||
test('create_shape rejects invalid type enum', async () => {
|
||||
await client.callTool({ name: 'new_document', arguments: {} })
|
||||
|
||||
const result = await client.callTool({
|
||||
name: 'create_shape',
|
||||
arguments: { type: 'INVALID_TYPE', x: 0, y: 0, width: 100, height: 100 }
|
||||
})
|
||||
const r = result as { content: { text: string }[]; isError?: boolean }
|
||||
const text = r.content[0].text
|
||||
expect(r.isError === true || text.toLowerCase().includes('invalid')).toBe(true)
|
||||
})
|
||||
|
||||
test('create_shape rejects missing required param', async () => {
|
||||
await client.callTool({ name: 'new_document', arguments: {} })
|
||||
|
||||
const result = await client.callTool({
|
||||
name: 'create_shape',
|
||||
arguments: { x: 0, y: 0, width: 100, height: 100 }
|
||||
})
|
||||
const r = result as { content: { text: string }[]; isError?: boolean }
|
||||
const text = r.content[0].text
|
||||
expect(r.isError === true || text.toLowerCase().includes('required')).toBe(true)
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in a new issue