|
1 | 1 | import { describe, it, expect } from 'vitest'; |
2 | 2 | import { |
3 | 3 | HttpMethod, |
| 4 | + HttpMethodSchema, |
| 5 | + HttpRequestSchema, |
4 | 6 | CorsConfigSchema, |
5 | 7 | RateLimitConfigSchema, |
6 | 8 | StaticMountSchema, |
@@ -134,3 +136,44 @@ describe('StaticMountSchema', () => { |
134 | 136 | expect(() => StaticMountSchema.parse({ path: '/static' })).toThrow(); |
135 | 137 | }); |
136 | 138 | }); |
| 139 | + |
| 140 | +// ============================================================================ |
| 141 | +// Issue #8: HttpMethodSchema and HttpRequestSchema migrated to shared |
| 142 | +// ============================================================================ |
| 143 | +describe('HttpMethodSchema (migrated from view.zod)', () => { |
| 144 | + it('should accept common HTTP methods', () => { |
| 145 | + const valid = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE']; |
| 146 | + valid.forEach(m => { |
| 147 | + expect(HttpMethodSchema.parse(m)).toBe(m); |
| 148 | + }); |
| 149 | + }); |
| 150 | + |
| 151 | + it('should reject HEAD and OPTIONS (subset for UI data sources)', () => { |
| 152 | + expect(() => HttpMethodSchema.parse('HEAD')).toThrow(); |
| 153 | + expect(() => HttpMethodSchema.parse('OPTIONS')).toThrow(); |
| 154 | + }); |
| 155 | +}); |
| 156 | + |
| 157 | +describe('HttpRequestSchema (migrated from view.zod)', () => { |
| 158 | + it('should accept minimal request with url only', () => { |
| 159 | + const result = HttpRequestSchema.parse({ url: 'https://api.example.com/data' }); |
| 160 | + expect(result.url).toBe('https://api.example.com/data'); |
| 161 | + expect(result.method).toBe('GET'); |
| 162 | + }); |
| 163 | + |
| 164 | + it('should accept full request with all fields', () => { |
| 165 | + const result = HttpRequestSchema.parse({ |
| 166 | + url: 'https://api.example.com/data', |
| 167 | + method: 'POST', |
| 168 | + headers: { 'Authorization': 'Bearer token' }, |
| 169 | + params: { page: 1 }, |
| 170 | + body: { name: 'test' }, |
| 171 | + }); |
| 172 | + expect(result.method).toBe('POST'); |
| 173 | + expect(result.headers?.['Authorization']).toBe('Bearer token'); |
| 174 | + }); |
| 175 | + |
| 176 | + it('should reject request without url', () => { |
| 177 | + expect(() => HttpRequestSchema.parse({})).toThrow(); |
| 178 | + }); |
| 179 | +}); |
0 commit comments