# Rental tests

These exercise the real `Database` class and the real functions from
`rentals.php` against a throwaway MySQL/MariaDB loaded from a dump. They are not
part of the request path; nothing in production requires them.

## Running

    # 1. load a dump into a THROWAWAY database named `vorta`
    mysql -e "CREATE DATABASE vorta"
    mysql vorta < your_dump.sql
    mysql vorta < ../migration_004_rental_sessions.sql

    # 2. point harness.php at it (edit the DSN line near the top)
    php test_returns.php
    php test_sync.php

`harness.php` reads `Database.class.php` off disk and rewrites the DSN in memory
so the class itself needs no test hooks. Do NOT run these against production —
they insert and delete invoice_items rows.

## What they cover

`test_returns.php` (28 assertions)
- partial returns accumulate instead of overwriting (the vanishing-quantity bug)
- the audit row records old -> new
- over-return is clamped to the line quantity
- `mode=set` corrects without breaking additive semantics
- serials merge across visits and dedupe
- `good + damaged + lost == qty` accepted; wrong totals rejected
- cannot mark more good/damaged than are physically back
- re-inspection supersedes and logs rather than overwriting
- a waived (zero) charge stays waived; a missing charge key stays on the legacy fallback
- the awaiting-inspection queue fills and empties
- timestamps land as epoch ints

`test_sync.php` (18 assertions)
- a `serials` PHP array binds without "Array to string conversion"
- session_id / inspected_at / charge_explicit / serials persist through push
- replaying the same batch stays idempotent
- the new UNIQUE key converges two differently-id'd rows onto one
- a delete op removes an inspection row
