From 3c379de5c47b05a6fa1884a09a87f2b82f5bfda2 Mon Sep 17 00:00:00 2001 From: DEls Date: Fri, 28 Aug 2026 12:48:42 +0200 Subject: [PATCH] test(plant-hours): cover unknown-QR deviation + value rounding Adds two tests that lock in behaviour the previous test file relied on implicitly: - validatePlantHoursRow rejects when the supplied vehicle's qr_code_id doesn't match row.vehicle_qr (the guard the schema extends beyond the original spec) - computePlantHoursFields rounds value to 2 decimal places (a fractional-input case the integer-only assertion didn't exercise) --- src/lib/plant-hours-schema.test.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/lib/plant-hours-schema.test.ts b/src/lib/plant-hours-schema.test.ts index 31fc27e..18a2244 100644 --- a/src/lib/plant-hours-schema.test.ts +++ b/src/lib/plant-hours-schema.test.ts @@ -41,6 +41,17 @@ describe("computePlantHoursFields", () => { expect(computePlantHoursFields(validRow).value).toBe(5735); // 31 * 185 = 5735 exactly }); + it("rounds value to 2 decimal places", () => { + // 31.5 * 185.25 = 5835.375, rounds to 5835.38 + const r = computePlantHoursFields({ + ...validRow, + start_hours: 1200, + end_hours: 1231.5, + hours: 31.5, + cost_per_hour: 185.25, + }); + expect(r.value).toBe(5835.38); + }); it("flags over_budget when hours > hour_meter_budget", () => { expect(computePlantHoursFields(validRow).over_budget).toBe(false); expect( @@ -72,6 +83,15 @@ describe("validatePlantHoursRow", () => { expect(r.errors[0]).toMatch(/unknown_vehicle_qr/); }); + it("rejects when supplied vehicle's QR doesn't match row QR", () => { + const r = validatePlantHoursRow( + validRow, // vehicle_qr is "QR-A" + { ...baseVehicle, qr_code_id: "QR-Z" }, // vehicle is defined but QR doesn't match + new Set(), + ); + expect(r.errors[0]).toMatch(/unknown_vehicle_qr/); + }); + it("rejects end_date < start_date", () => { const r = validatePlantHoursRow( { ...validRow, end_date: "2026-08-23" },