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",
|
"front",
|
||||||
"seitlich_rechts",
|
"seitlich_rechts",
|
||||||
"rechte_seite",
|
"rechte_seite",
|
||||||
|
|
@ -9,4 +9,4 @@ export const PFLICHT_FOTO_POSITIONEN = [
|
||||||
"seitlich_vorne_links",
|
"seitlich_vorne_links",
|
||||||
] as const;
|
] 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 { createClient } from "@/lib/supabase/server";
|
||||||
import { PFLICHT_FOTO_POSITIONEN } from "./foto-positionen";
|
import { STANDARD_FOTO_POSITIONEN } from "./foto-positionen";
|
||||||
|
|
||||||
export type AuftragFoto = {
|
export type AuftragFoto = {
|
||||||
position: string;
|
position: string;
|
||||||
|
|
@ -15,7 +15,7 @@ export type FotoZeile = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export function sortiereUndBeschrifteFotos(fotos: FotoZeile[]): (FotoZeile & { label: string })[] {
|
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)
|
fotos.find((foto) => foto.position === position)
|
||||||
).filter((foto): foto is FotoZeile => foto !== undefined);
|
).filter((foto): foto is FotoZeile => foto !== undefined);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,43 +1,21 @@
|
||||||
import { describe, expect, it } from "vitest";
|
import { describe, expect, it } from "vitest";
|
||||||
import { validateFahrtBeginn, validateFahrtEnde } from "./validate-fahrt";
|
import { validateFahrtBeginn, validateFahrtEnde } from "./validate-fahrt";
|
||||||
import { PFLICHT_FOTO_POSITIONEN } from "./foto-positionen";
|
|
||||||
|
|
||||||
describe("validateFahrtBeginn", () => {
|
describe("validateFahrtBeginn", () => {
|
||||||
it("akzeptiert gueltigen KM-Stand mit allen 8 Pflichtfotos", () => {
|
it("akzeptiert einen gueltigen KM-Stand", () => {
|
||||||
const result = validateFahrtBeginn({
|
const result = validateFahrtBeginn({ startKm: "12345" });
|
||||||
startKm: "12345",
|
|
||||||
vorhandenePositionen: [...PFLICHT_FOTO_POSITIONEN],
|
|
||||||
});
|
|
||||||
expect(result).toEqual({ valid: true, startKm: 12345 });
|
expect(result).toEqual({ valid: true, startKm: 12345 });
|
||||||
});
|
});
|
||||||
|
|
||||||
it("lehnt einen fehlenden KM-Stand ab", () => {
|
it("lehnt einen fehlenden KM-Stand ab", () => {
|
||||||
const result = validateFahrtBeginn({
|
const result = validateFahrtBeginn({ startKm: "" });
|
||||||
startKm: "",
|
|
||||||
vorhandenePositionen: [...PFLICHT_FOTO_POSITIONEN],
|
|
||||||
});
|
|
||||||
expect(result).toEqual({ valid: false, error: "Bitte einen KM-Stand eingeben." });
|
expect(result).toEqual({ valid: false, error: "Bitte einen KM-Stand eingeben." });
|
||||||
});
|
});
|
||||||
|
|
||||||
it("lehnt einen negativen KM-Stand ab", () => {
|
it("lehnt einen negativen KM-Stand ab", () => {
|
||||||
const result = validateFahrtBeginn({
|
const result = validateFahrtBeginn({ startKm: "-5" });
|
||||||
startKm: "-5",
|
|
||||||
vorhandenePositionen: [...PFLICHT_FOTO_POSITIONEN],
|
|
||||||
});
|
|
||||||
expect(result).toEqual({ valid: false, error: "Der KM-Stand darf nicht negativ sein." });
|
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", () => {
|
describe("validateFahrtEnde", () => {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,3 @@
|
||||||
import { PFLICHT_FOTO_POSITIONEN } from "./foto-positionen";
|
|
||||||
|
|
||||||
export type FahrtBeginnValidationResult =
|
export type FahrtBeginnValidationResult =
|
||||||
| { valid: true; startKm: number }
|
| { valid: true; startKm: number }
|
||||||
| { valid: false; error: string };
|
| { valid: false; error: string };
|
||||||
|
|
@ -16,10 +14,7 @@ function parseKm(value: FormDataEntryValue | null): number | null {
|
||||||
return Number.isFinite(parsed) ? parsed : null;
|
return Number.isFinite(parsed) ? parsed : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function validateFahrtBeginn(input: {
|
export function validateFahrtBeginn(input: { startKm: FormDataEntryValue | null }): FahrtBeginnValidationResult {
|
||||||
startKm: FormDataEntryValue | null;
|
|
||||||
vorhandenePositionen: string[];
|
|
||||||
}): FahrtBeginnValidationResult {
|
|
||||||
const startKm = parseKm(input.startKm);
|
const startKm = parseKm(input.startKm);
|
||||||
if (startKm === null) {
|
if (startKm === null) {
|
||||||
return { valid: false, error: "Bitte einen KM-Stand eingeben." };
|
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." };
|
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 };
|
return { valid: true, startKm };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue