|
| 1 | +import { describe, expect, it } from 'vitest'; |
| 2 | +import { toolCommandSchema } from './configuration.js'; |
| 3 | + |
| 4 | +describe('toolCommandSchema', () => { |
| 5 | + it('should validate a command with required fields', () => { |
| 6 | + const data = { command: 'npx' }; |
| 7 | + const result = toolCommandSchema.safeParse(data); |
| 8 | + expect(result.success).toBe(true); |
| 9 | + if (result.success) { |
| 10 | + expect(result.data.command).toBe('npx'); |
| 11 | + expect(result.data.args).toBeUndefined(); |
| 12 | + } |
| 13 | + }); |
| 14 | + |
| 15 | + it('should validate a command with args', () => { |
| 16 | + const data = { command: 'npx', args: ['eslint', 'src/'] }; |
| 17 | + const result = toolCommandSchema.safeParse(data); |
| 18 | + expect(result.success).toBe(true); |
| 19 | + if (result.success) { |
| 20 | + expect(result.data.command).toBe('npx'); |
| 21 | + expect(result.data.args).toEqual(['eslint', 'src/']); |
| 22 | + } |
| 23 | + }); |
| 24 | + |
| 25 | + it('should fail if command is missing', () => { |
| 26 | + const data = { args: ['eslint', 'src/'] }; |
| 27 | + const result = toolCommandSchema.safeParse(data); |
| 28 | + expect(result.success).toBe(false); |
| 29 | + }); |
| 30 | + |
| 31 | + it('should fail if command is empty', () => { |
| 32 | + const data = { command: '' }; |
| 33 | + const result = toolCommandSchema.safeParse(data); |
| 34 | + expect(result.success).toBe(false); |
| 35 | + }); |
| 36 | + |
| 37 | + it('should fail if args is not an array of strings', () => { |
| 38 | + const data = { command: 'npx', args: [123, true] }; |
| 39 | + const result = toolCommandSchema.safeParse(data); |
| 40 | + expect(result.success).toBe(false); |
| 41 | + }); |
| 42 | +}); |
0 commit comments