-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into add_pdf_table_info_annuellierung
- Loading branch information
Showing
4 changed files
with
61 additions
and
1 deletion.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
app/domains/fluggastrechte/vorabcheck/multiFieldsValidation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; |
31 changes: 31 additions & 0 deletions
31
app/domains/fluggastrechte/vorabcheck/services/__test__/validation.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
21
app/domains/fluggastrechte/vorabcheck/services/validation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}), | ||
); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters