Files
app/src/__tests__/trips-vehicles-km-int.test.ts
BOHA e11765bf0e fix: resolve all 28 findings from the 2026-06-12 full audit (TDD-pinned)
Critical (data integrity):
- warehouse inventory confirm: throw (not return) inside $transaction so a
  failed deficit line rolls back the surplus corrective receipt — retries
  no longer accumulate phantom stock
- warehouse issue confirm: validate batches against the COMBINED quantity
  of all lines (duplicate FIFO-resolved lines drove batches negative)
- attendance delete: restore vacation_used/sick_used for the deleted day
  (in-transaction, clamped at 0)

High:
- auth refresh: terminated sessions (replaced_at only) get a plain 401 —
  the theft branch (family revocation) now fires only on replaced_by_hash
- POST /users strips role_id for non-admin callers (mirrors PUT guard)
- issued-order transition flushes unsaved edits via the full save payload
  when dirty; server contract (items+status in one PUT) pinned
- received-invoices list: usePaginatedQuery + pager (rows 26+ unreachable)
- received-invoice dates: nullableIsoDateString + NaN guard before NAS save
  (Czech-format dates corrupted month/year, orphaned NAS files)
- leave approval skips Czech public holidays and books each calendar year's
  hours against its own balance (mirrors createLeave)

Medium/Low (classes):
- 52 Zod caps aligned to DB column widths across 7 schemas (over-cap input
  500ed at Prisma instead of a Czech 400)
- FK pre-validation: projects update + warehouse receipts/issues return
  Czech 400s instead of P2003 500s
- invoice PDF degrades gracefully when the CNB rate is unavailable
  (recap omitted instead of 500 + lost NAS archival)
- date boundaries: local-day filters (warehouse lists/reports, audit-log),
  @db.Date coercion on invoice dates
- plan updateEntry re-checks the per-cell cap (self-excluding)
- {id} tiebreaks on customers/received-invoices/warehouse-items sorts;
  /items honors the client sort param
- htmlToPdf relaunches once when the shared browser died mid-render
- offer number release parses the year from the document number (cross-year
  finalize+delete left permanent sequence gaps)
- trips/vehicles km fields integer-coerced; AI budget regated to
  settings.company|settings.system; Settings System tab no longer clobbers
  Firma numbering patterns; draft invoices hide the dead PDF button;
  dashboard quick-trip invalidates ["vehicles"]; TOTP secret cap 64;
  audit-log + invoice month buckets day-shift fixes

Docs: corrected the stale "Chromium has no CSS margin-box footers" claim
(html-to-pdf.ts + CLAUDE.md — margin boxes render since Chrome 131); audit
report M3 withdrawn accordingly.

~65 new pinning tests; every finding reproduced RED against the real test
DB before its fix. Suite: 58 files / 634 tests green.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-12 23:00:19 +02:00

64 lines
1.7 KiB
TypeScript

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,
);
});
});