import { describe, it, expect } from "vitest"; import { CreateTripSchema, UpdateTripSchema } from "../schemas/trips.schema"; import { CreateVehicleSchema, UpdateVehicleSchema, } from "../schemas/vehicles.schema"; /** * Pinning tests for audit finding L7: odometer fields are Int columns — * a decimal reading must 400 at Zod instead of 500ing at Prisma (or * silently truncating, corrupting the derived distance and * vehicles.actual_km). */ const tripBase = { vehicle_id: 1, trip_date: "2098-01-15", start_km: 100, end_km: 200, route_from: "A", route_to: "B", }; describe("km fields are integers (audit L7)", () => { it.each([["start_km"], ["end_km"]])( "CreateTripSchema rejects a decimal %s", (field) => { expect( CreateTripSchema.safeParse({ ...tripBase, [field]: 100.5 }).success, ).toBe(false); }, ); it("CreateTripSchema still accepts integer readings", () => { expect(CreateTripSchema.safeParse(tripBase).success).toBe(true); }); it("UpdateTripSchema rejects a decimal start_km", () => { expect(UpdateTripSchema.safeParse({ start_km: 100.5 }).success).toBe(false); }); it.each([["initial_km"], ["actual_km"]])( "CreateVehicleSchema rejects a decimal %s", (field) => { expect( CreateVehicleSchema.safeParse({ spz: "1AB 1234", name: "Test", [field]: 12345.5, }).success, ).toBe(false); }, ); it("UpdateVehicleSchema rejects a decimal actual_km, accepts an integer", () => { expect(UpdateVehicleSchema.safeParse({ actual_km: 12345.5 }).success).toBe( false, ); expect(UpdateVehicleSchema.safeParse({ actual_km: 12345 }).success).toBe( true, ); }); });