fix: Prefill issue when name isn't present and add unit tests (#11418)

* Fix yarn.lock

* Add tests for getBookingResponsesSchema

* Fix prefill failing if name isnt provided

* More tests and another fix
This commit is contained in:
Hariom Balhara authored and GitHub committed 2023-09-26 16:16:31 +05:30
1 parent a0642598ab
commit 4acfb4b28c
4 files changed
+1048 -12

No files matched your search

+4 -2
View File
@@ -5,6 +5,8 @@ import { getValidRhfFieldName } from "@calcom/lib/getValidRhfFieldName";
import { fieldTypesConfigMap } from "./fieldTypes";
import { getVariantsConfig, preprocessNameFieldDataWithVariant } from "./utils";
const nonEmptyString = () => z.string().refine((value: string) => value.trim().length > 0);
const fieldTypeEnum = z.enum([
"name",
"text",
@@ -289,7 +291,7 @@ export const fieldTypesSchemaMap: Partial<
if (fields.length === 1) {
const field = fields[0];
if (variantSupportedFields.includes(field.type)) {
const schema = stringSchema;
const schema = field.required && !isPartialSchema ? nonEmptyString() : stringSchema;
if (!schema.safeParse(response).success) {
ctx.addIssue({ code: z.ZodIssueCode.custom, message: m("Invalid string") });
}
@@ -299,7 +301,7 @@ export const fieldTypesSchemaMap: Partial<
}
}
fields.forEach((subField) => {
const schema = stringSchema;
const schema = subField.required && !isPartialSchema ? nonEmptyString() : stringSchema;
if (!variantSupportedFields.includes(subField.type)) {
throw new Error(`Unsupported field.type with variants: ${subField.type}`);
}