|
|
@@ -51,6 +51,46 @@ describe('form-schema-tools', () => {
|
|
|
expect(() => schema.parse(123)).toThrow();
|
|
|
});
|
|
|
|
|
|
+ it('should reject empty strings for non-nullable String fields', () => {
|
|
|
+ const field = createMockField('name', 'String', false);
|
|
|
+ const schema = getZodTypeFromField(field);
|
|
|
+
|
|
|
+ expect(() => schema.parse('test')).not.toThrow();
|
|
|
+ expect(() => schema.parse('')).toThrow();
|
|
|
+
|
|
|
+ try {
|
|
|
+ schema.parse('');
|
|
|
+ expect.fail('Should have thrown validation error');
|
|
|
+ } catch (error: any) {
|
|
|
+ expect(error.errors[0].message).toBe('This field is required');
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ it('should accept empty strings for nullable String fields', () => {
|
|
|
+ const field = createMockField('name', 'String', true);
|
|
|
+ const schema = getZodTypeFromField(field);
|
|
|
+
|
|
|
+ expect(() => schema.parse('test')).not.toThrow();
|
|
|
+ expect(() => schema.parse('')).not.toThrow();
|
|
|
+ expect(() => schema.parse(null)).not.toThrow();
|
|
|
+ });
|
|
|
+
|
|
|
+ it('should reject empty strings for non-nullable ID fields', () => {
|
|
|
+ const field = createMockField('id', 'ID', false);
|
|
|
+ const schema = getZodTypeFromField(field);
|
|
|
+
|
|
|
+ expect(() => schema.parse('123')).not.toThrow();
|
|
|
+ expect(() => schema.parse('')).toThrow();
|
|
|
+ });
|
|
|
+
|
|
|
+ it('should reject empty strings for non-nullable DateTime fields', () => {
|
|
|
+ const field = createMockField('date', 'DateTime', false);
|
|
|
+ const schema = getZodTypeFromField(field);
|
|
|
+
|
|
|
+ expect(() => schema.parse('2024-01-01')).not.toThrow();
|
|
|
+ expect(() => schema.parse('')).toThrow();
|
|
|
+ });
|
|
|
+
|
|
|
it('should create number type for Int fields', () => {
|
|
|
const field = createMockField('age', 'Int');
|
|
|
const schema = getZodTypeFromField(field);
|