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)
This commit is contained in:
parent
4b5c93da37
commit
3c379de5c4
1 changed files with 20 additions and 0 deletions
|
|
@ -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" },
|
||||
|
|
|
|||
Loading…
Reference in a new issue