forked from fahrPool/fahrPool
feat: make Fahrtbeginn photos optional, rename PFLICHT_FOTO_POSITIONEN to STANDARD_FOTO_POSITIONEN
This commit is contained in:
parent
6137dac74d
commit
76c555a292
|
|
@ -1,4 +1,4 @@
|
|||
export const PFLICHT_FOTO_POSITIONEN = [
|
||||
export const STANDARD_FOTO_POSITIONEN = [
|
||||
"front",
|
||||
"seitlich_rechts",
|
||||
"rechte_seite",
|
||||
|
|
@ -9,4 +9,4 @@ export const PFLICHT_FOTO_POSITIONEN = [
|
|||
"seitlich_vorne_links",
|
||||
] as const;
|
||||
|
||||
export type PflichtFotoPosition = (typeof PFLICHT_FOTO_POSITIONEN)[number];
|
||||
export type StandardFotoPosition = (typeof STANDARD_FOTO_POSITIONEN)[number];
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { createClient } from "@/lib/supabase/server";
|
||||
import { PFLICHT_FOTO_POSITIONEN } from "./foto-positionen";
|
||||
import { STANDARD_FOTO_POSITIONEN } from "./foto-positionen";
|
||||
|
||||
export type AuftragFoto = {
|
||||
position: string;
|
||||
|
|
@ -15,7 +15,7 @@ export type FotoZeile = {
|
|||
};
|
||||
|
||||
export function sortiereUndBeschrifteFotos(fotos: FotoZeile[]): (FotoZeile & { label: string })[] {
|
||||
const pflichtFotos = PFLICHT_FOTO_POSITIONEN.map((position) =>
|
||||
const pflichtFotos = STANDARD_FOTO_POSITIONEN.map((position) =>
|
||||
fotos.find((foto) => foto.position === position)
|
||||
).filter((foto): foto is FotoZeile => foto !== undefined);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,43 +1,21 @@
|
|||
import { describe, expect, it } from "vitest";
|
||||
import { validateFahrtBeginn, validateFahrtEnde } from "./validate-fahrt";
|
||||
import { PFLICHT_FOTO_POSITIONEN } from "./foto-positionen";
|
||||
|
||||
describe("validateFahrtBeginn", () => {
|
||||
it("akzeptiert gueltigen KM-Stand mit allen 8 Pflichtfotos", () => {
|
||||
const result = validateFahrtBeginn({
|
||||
startKm: "12345",
|
||||
vorhandenePositionen: [...PFLICHT_FOTO_POSITIONEN],
|
||||
});
|
||||
it("akzeptiert einen gueltigen KM-Stand", () => {
|
||||
const result = validateFahrtBeginn({ startKm: "12345" });
|
||||
expect(result).toEqual({ valid: true, startKm: 12345 });
|
||||
});
|
||||
|
||||
it("lehnt einen fehlenden KM-Stand ab", () => {
|
||||
const result = validateFahrtBeginn({
|
||||
startKm: "",
|
||||
vorhandenePositionen: [...PFLICHT_FOTO_POSITIONEN],
|
||||
});
|
||||
const result = validateFahrtBeginn({ startKm: "" });
|
||||
expect(result).toEqual({ valid: false, error: "Bitte einen KM-Stand eingeben." });
|
||||
});
|
||||
|
||||
it("lehnt einen negativen KM-Stand ab", () => {
|
||||
const result = validateFahrtBeginn({
|
||||
startKm: "-5",
|
||||
vorhandenePositionen: [...PFLICHT_FOTO_POSITIONEN],
|
||||
});
|
||||
const result = validateFahrtBeginn({ startKm: "-5" });
|
||||
expect(result).toEqual({ valid: false, error: "Der KM-Stand darf nicht negativ sein." });
|
||||
});
|
||||
|
||||
it("lehnt fehlende Pflichtfotos ab und benennt die fehlenden Positionen", () => {
|
||||
const result = validateFahrtBeginn({
|
||||
startKm: "12345",
|
||||
vorhandenePositionen: ["front", "heck"],
|
||||
});
|
||||
expect(result).toEqual({
|
||||
valid: false,
|
||||
error:
|
||||
"Es fehlen noch 6 Pflichtfoto(s): seitlich_rechts, rechte_seite, seitlich_rechts_heck, seitlich_links_heck, linke_seite, seitlich_vorne_links",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("validateFahrtEnde", () => {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
import { PFLICHT_FOTO_POSITIONEN } from "./foto-positionen";
|
||||
|
||||
export type FahrtBeginnValidationResult =
|
||||
| { valid: true; startKm: number }
|
||||
| { valid: false; error: string };
|
||||
|
|
@ -16,10 +14,7 @@ function parseKm(value: FormDataEntryValue | null): number | null {
|
|||
return Number.isFinite(parsed) ? parsed : null;
|
||||
}
|
||||
|
||||
export function validateFahrtBeginn(input: {
|
||||
startKm: FormDataEntryValue | null;
|
||||
vorhandenePositionen: string[];
|
||||
}): FahrtBeginnValidationResult {
|
||||
export function validateFahrtBeginn(input: { startKm: FormDataEntryValue | null }): FahrtBeginnValidationResult {
|
||||
const startKm = parseKm(input.startKm);
|
||||
if (startKm === null) {
|
||||
return { valid: false, error: "Bitte einen KM-Stand eingeben." };
|
||||
|
|
@ -28,15 +23,6 @@ export function validateFahrtBeginn(input: {
|
|||
return { valid: false, error: "Der KM-Stand darf nicht negativ sein." };
|
||||
}
|
||||
|
||||
const vorhanden = new Set(input.vorhandenePositionen);
|
||||
const fehlend = PFLICHT_FOTO_POSITIONEN.filter((position) => !vorhanden.has(position));
|
||||
if (fehlend.length > 0) {
|
||||
return {
|
||||
valid: false,
|
||||
error: `Es fehlen noch ${fehlend.length} Pflichtfoto(s): ${fehlend.join(", ")}`,
|
||||
};
|
||||
}
|
||||
|
||||
return { valid: true, startKm };
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue