* Make identifier required * Fallback to null if identifier isn't present * Type fix * Type fixes * Type fix * Create `RoutingFormResponseRepository` * Create `RoutingFormResponseService` * Use repsotiories to find form value * Delete console.logs * Undo change in `ZResponseInputSchema` schema * Type fix * Undo changes * fix: correct import path in RoutingFormResponseService to resolve runtime errors - Change relative import path to use @calcom alias - Prevents import resolution failures that cause app startup issues Co-Authored-By: joe@cal.com <j.auyeung419@gmail.com> * Undo changes * Update type * Update typing * Address feedback * Address feedback * chore: Provide a suggestion for pr 22396, new structure (#22491) * chore: Provide a suggestion for pr 22396, new structure * Refactor to create two create methods with bookingUid and id * Use `createWithBookingUid` * Extract routing form response parser to seperate util * Added more and improved test cases * Fix --------- Co-authored-by: Joe Au-Yeung <j.auyeung419@gmail.com> * Factory included wrong calls * Fix test for findFieldValueByIdentifier * Add tests * Fix test * Fix test --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Alex van Andel <me@alexvanandel.com>
34 lines
1.2 KiB
TypeScript
34 lines
1.2 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
|
|
|
import { findFieldValueByIdentifier } from "./findFieldValueByIdentifier";
|
|
import type { RoutingFormResponseData } from "./types";
|
|
|
|
describe("findFieldValueByIdentifier", () => {
|
|
const responseData: RoutingFormResponseData = {
|
|
response: {
|
|
"field-123": { value: "test@example.com" },
|
|
"field-456": { value: "John Doe" },
|
|
},
|
|
fields: [
|
|
{ id: "field-123", label: "E-mail", identifier: "email", type: "text" },
|
|
{ id: "field-456", label: "Name", identifier: "name", type: "text" },
|
|
],
|
|
};
|
|
|
|
it("returns the correct value for an existing field identifier", async () => {
|
|
const result = findFieldValueByIdentifier(responseData, "email");
|
|
expect(result.success).toBe(true);
|
|
// @ts-expect-error we know data is defined here
|
|
expect(result.data).toBe("test@example.com");
|
|
});
|
|
|
|
it("throws an error and logs when identifier is not found", () => {
|
|
const invalidIdentifier = "unknown";
|
|
|
|
const result = findFieldValueByIdentifier(responseData, invalidIdentifier);
|
|
expect(result.success).toBe(false);
|
|
// @ts-expect-error we know error is defined here
|
|
expect(result.error).toBe(`Field with identifier ${invalidIdentifier} not found`);
|
|
});
|
|
});
|