forked from fahrPool/fahrPool
62 lines
2.2 KiB
TypeScript
62 lines
2.2 KiB
TypeScript
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],
|
|
});
|
|
expect(result).toEqual({ valid: true, startKm: 12345 });
|
|
});
|
|
|
|
it("lehnt einen fehlenden KM-Stand ab", () => {
|
|
const result = validateFahrtBeginn({
|
|
startKm: "",
|
|
vorhandenePositionen: [...PFLICHT_FOTO_POSITIONEN],
|
|
});
|
|
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],
|
|
});
|
|
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", () => {
|
|
it("akzeptiert einen End-KM-Stand groesser als der Start-KM-Stand", () => {
|
|
const result = validateFahrtEnde({ endKm: "12500", startKm: 12345 });
|
|
expect(result).toEqual({ valid: true, endKm: 12500 });
|
|
});
|
|
|
|
it("lehnt einen fehlenden End-KM-Stand ab", () => {
|
|
const result = validateFahrtEnde({ endKm: "", startKm: 12345 });
|
|
expect(result).toEqual({ valid: false, error: "Bitte einen End-KM-Stand eingeben." });
|
|
});
|
|
|
|
it("lehnt einen End-KM-Stand kleiner als der Start-KM-Stand ab", () => {
|
|
const result = validateFahrtEnde({ endKm: "100", startKm: 12345 });
|
|
expect(result).toEqual({
|
|
valid: false,
|
|
error: "Der End-KM-Stand darf nicht kleiner als der Start-KM-Stand (12345) sein.",
|
|
});
|
|
});
|
|
});
|