mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-30 00:20:07 +00:00
9650ad4597
New tripInviteLinkCreateRequestSchema in @trek/shared (single source of truth), a createZodDto wrapper on the controller's raw @Body(), and the TripInviteLinkController.create entry dropped from the body-contract allow-list (the boot ratchet enforces it). expires_in_days accepts number | digits-only string | null | absent — the string branch is digits-only so garbage like "7abc" is a 400 instead of silently parseInt-ing to 7; the empty string (blank form input, meaning no expiry) stays accepted. The e2e registers ZodValidationPipe and pins both the bounded-expiry and 400 paths.
34 lines
1.6 KiB
TypeScript
34 lines
1.6 KiB
TypeScript
import { tripInviteLinkCreateRequestSchema } from './trip-invite.schema';
|
|
|
|
import { describe, it, expect } from 'vitest';
|
|
|
|
describe('tripInviteLinkCreateRequestSchema', () => {
|
|
it('accepts an empty body (no expiry chosen)', () => {
|
|
expect(tripInviteLinkCreateRequestSchema.safeParse({}).success).toBe(true);
|
|
});
|
|
|
|
it('accepts an explicit null (the client always sends the key)', () => {
|
|
expect(tripInviteLinkCreateRequestSchema.safeParse({ expires_in_days: null }).success).toBe(true);
|
|
});
|
|
|
|
it('accepts a number and a digits-only string (legacy form input)', () => {
|
|
expect(tripInviteLinkCreateRequestSchema.safeParse({ expires_in_days: 7 }).success).toBe(true);
|
|
expect(tripInviteLinkCreateRequestSchema.safeParse({ expires_in_days: '7' }).success).toBe(true);
|
|
});
|
|
|
|
it('accepts the empty string (blank form input means no expiry)', () => {
|
|
expect(tripInviteLinkCreateRequestSchema.safeParse({ expires_in_days: '' }).success).toBe(true);
|
|
});
|
|
|
|
it('rejects non-numeric strings instead of parseInt-ing them', () => {
|
|
expect(tripInviteLinkCreateRequestSchema.safeParse({ expires_in_days: '7abc' }).success).toBe(false);
|
|
expect(tripInviteLinkCreateRequestSchema.safeParse({ expires_in_days: 'never' }).success).toBe(false);
|
|
});
|
|
|
|
it('rejects non-scalar values', () => {
|
|
expect(tripInviteLinkCreateRequestSchema.safeParse({ expires_in_days: {} }).success).toBe(false);
|
|
expect(tripInviteLinkCreateRequestSchema.safeParse({ expires_in_days: [7] }).success).toBe(false);
|
|
expect(tripInviteLinkCreateRequestSchema.safeParse({ expires_in_days: true }).success).toBe(false);
|
|
});
|
|
});
|