|
5 | 5 | GetDataResponseSchema, |
6 | 6 | FindDataRequestSchema, |
7 | 7 | FindDataResponseSchema, |
| 8 | + HttpFindQueryParamsSchema, |
8 | 9 | CreateDataRequestSchema, |
9 | 10 | CreateDataResponseSchema, |
10 | 11 | UpdateDataRequestSchema, |
@@ -367,3 +368,102 @@ describe('GetDiscoveryResponseSchema (capabilities)', () => { |
367 | 368 | expect(result.success).toBe(false); |
368 | 369 | }); |
369 | 370 | }); |
| 371 | + |
| 372 | +// ========================================== |
| 373 | +// GetDataRequestSchema — select/expand params |
| 374 | +// ========================================== |
| 375 | + |
| 376 | +describe('GetDataRequestSchema (select/expand)', () => { |
| 377 | + it('should accept request with select and expand', () => { |
| 378 | + const result = GetDataRequestSchema.safeParse({ |
| 379 | + object: 'contact', |
| 380 | + id: 'c1', |
| 381 | + select: ['name', 'email'], |
| 382 | + expand: ['account', 'owner'], |
| 383 | + }); |
| 384 | + expect(result.success).toBe(true); |
| 385 | + if (result.success) { |
| 386 | + expect(result.data.select).toEqual(['name', 'email']); |
| 387 | + expect(result.data.expand).toEqual(['account', 'owner']); |
| 388 | + } |
| 389 | + }); |
| 390 | + |
| 391 | + it('should accept request without select/expand (optional)', () => { |
| 392 | + const result = GetDataRequestSchema.safeParse({ |
| 393 | + object: 'contact', |
| 394 | + id: 'c1', |
| 395 | + }); |
| 396 | + expect(result.success).toBe(true); |
| 397 | + if (result.success) { |
| 398 | + expect(result.data.select).toBeUndefined(); |
| 399 | + expect(result.data.expand).toBeUndefined(); |
| 400 | + } |
| 401 | + }); |
| 402 | + |
| 403 | + it('should strip unknown query parameters via strict parsing', () => { |
| 404 | + const result = GetDataRequestSchema.strict().safeParse({ |
| 405 | + object: 'contact', |
| 406 | + id: 'c1', |
| 407 | + select: ['name'], |
| 408 | + // Unknown params that should be rejected by strict mode |
| 409 | + unknownParam: 'should-be-stripped', |
| 410 | + }); |
| 411 | + expect(result.success).toBe(false); |
| 412 | + }); |
| 413 | +}); |
| 414 | + |
| 415 | +// ========================================== |
| 416 | +// HttpFindQueryParamsSchema — HTTP parameter naming |
| 417 | +// ========================================== |
| 418 | + |
| 419 | +describe('HttpFindQueryParamsSchema', () => { |
| 420 | + it('should accept canonical filter (singular) parameter', () => { |
| 421 | + const result = HttpFindQueryParamsSchema.safeParse({ |
| 422 | + filter: '{"status":"active"}', |
| 423 | + select: 'name,email', |
| 424 | + top: 10, |
| 425 | + }); |
| 426 | + expect(result.success).toBe(true); |
| 427 | + if (result.success) { |
| 428 | + expect(result.data.filter).toBe('{"status":"active"}'); |
| 429 | + expect(result.data.top).toBe(10); |
| 430 | + } |
| 431 | + }); |
| 432 | + |
| 433 | + it('should accept deprecated filters (plural) parameter for backward compat', () => { |
| 434 | + const result = HttpFindQueryParamsSchema.safeParse({ |
| 435 | + filters: '{"status":"active"}', |
| 436 | + }); |
| 437 | + expect(result.success).toBe(true); |
| 438 | + if (result.success) { |
| 439 | + expect(result.data.filters).toBe('{"status":"active"}'); |
| 440 | + } |
| 441 | + }); |
| 442 | + |
| 443 | + it('should coerce string numbers for top/skip', () => { |
| 444 | + const result = HttpFindQueryParamsSchema.safeParse({ |
| 445 | + top: '25', |
| 446 | + skip: '50', |
| 447 | + }); |
| 448 | + expect(result.success).toBe(true); |
| 449 | + if (result.success) { |
| 450 | + expect(result.data.top).toBe(25); |
| 451 | + expect(result.data.skip).toBe(50); |
| 452 | + } |
| 453 | + }); |
| 454 | + |
| 455 | + it('should accept sort, orderBy, expand, search, distinct, count', () => { |
| 456 | + const result = HttpFindQueryParamsSchema.safeParse({ |
| 457 | + sort: 'name asc,created_at desc', |
| 458 | + expand: 'owner,account', |
| 459 | + search: 'John', |
| 460 | + distinct: true, |
| 461 | + count: true, |
| 462 | + }); |
| 463 | + expect(result.success).toBe(true); |
| 464 | + }); |
| 465 | + |
| 466 | + it('should accept empty object (all params optional)', () => { |
| 467 | + expect(HttpFindQueryParamsSchema.safeParse({}).success).toBe(true); |
| 468 | + }); |
| 469 | +}); |
0 commit comments