Skip to content

Commit

Permalink
Merge branch 'main' into add_pdf_table_info_annuellierung
Browse files Browse the repository at this point in the history
  • Loading branch information
aaschlote authored Jan 9, 2025
2 parents 18cde25 + cc074e6 commit 8f41eb2
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { MultiFieldsStepIdValidation } from "~/domains/multiFieldsFlowValidation";
import { validateSameDepartureAndArrivalAirports } from "./services/validation";

export const fluggastrechtVorabcheckMultiFieldsValidation: MultiFieldsStepIdValidation =
{
"/flughaefen": validateSameDepartureAndArrivalAirports,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { z } from "zod";
import { validateSameDepartureAndArrivalAirports } from "../validation";

describe("Vorabcheck - Multi Fields Validation", () => {
describe("validateSameDepartureAndArrivalAirports", () => {
const baseSchema = z.object({
startAirport: z.string(),
endAirport: z.string(),
});

const validator = validateSameDepartureAndArrivalAirports(baseSchema);

it("should return success false when startAirport and endAirport are the same", () => {
const result = validator.safeParse({
startAirport: "JFK",
endAirport: "JFK",
});

expect(result.success).toBe(false);
});

it("should return success true when startAirport and endAirport are different", () => {
const result = validator.safeParse({
startAirport: "JFK",
endAirport: "LAX",
});

expect(result.success).toBe(true);
});
});
});
21 changes: 21 additions & 0 deletions app/domains/fluggastrechte/vorabcheck/services/validation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { z } from "zod";
import type { MultiFieldsValidationBaseSchema } from "~/domains/multiFieldsFlowValidation";

export function validateSameDepartureAndArrivalAirports(
baseSchema: MultiFieldsValidationBaseSchema,
) {
const fieldsToValidate = ["startAirport", "endAirport"];

return baseSchema.superRefine((data, ctx) => {
if (data.startAirport === data.endAirport) {
fieldsToValidate.forEach((field) =>
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: "sameDepartureAndArrivalAirports",
path: [field],
fatal: true,
}),
);
}
});
}
3 changes: 2 additions & 1 deletion app/domains/multiFieldsFlowValidation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { z } from "zod";
import type { FlowId } from "./flowIds";
import { fluggastrechtMultiFieldsValidation } from "./fluggastrechte/formular/multiFieldsValidation";
import { fluggastrechtVorabcheckMultiFieldsValidation } from "./fluggastrechte/vorabcheck/multiFieldsValidation";

export type MultiFieldsValidationBaseSchema = z.ZodObject<
Record<string, z.ZodTypeAny>
Expand All @@ -20,7 +21,7 @@ const multiFieldsFlowValidation = {
"/beratungshilfe/vorabcheck": undefined,
"/geld-einklagen/vorabcheck": undefined,
"/geld-einklagen/formular": undefined,
"/fluggastrechte/vorabcheck": undefined,
"/fluggastrechte/vorabcheck": fluggastrechtVorabcheckMultiFieldsValidation,
"/fluggastrechte/formular": fluggastrechtMultiFieldsValidation,
"/prozesskostenhilfe/formular": undefined,
} as const satisfies Record<FlowId, MultiFieldsStepIdValidation | undefined>;
Expand Down

0 comments on commit 8f41eb2

Please sign in to comment.