1
0
Fork 0
fahrPool/web/lib/auftraege/validate-fahrt.test.ts

40 lines
1.5 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { validateFahrtBeginn, validateFahrtEnde } from "./validate-fahrt";
describe("validateFahrtBeginn", () => {
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: "" });
expect(result).toEqual({ valid: false, error: "Bitte einen KM-Stand eingeben." });
});
it("lehnt einen negativen KM-Stand ab", () => {
const result = validateFahrtBeginn({ startKm: "-5" });
expect(result).toEqual({ valid: false, error: "Der KM-Stand darf nicht negativ sein." });
});
});
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.",
});
});
});