Files
api/services/nginx/app/tests/Unit/Orders/OrderLastWashTimestampForPlateTest.php
T
openclaw bugfix 7ac90f70c9 feat(api): expose last_wash timestamp on /numberplatescans (TRU-78)
When the operator scans a license plate on the POS landing page, the
frontend now needs to display 'last washed' so they can decide whether a
DHL trailer needs another wash before pick-up (DRIFT 17).

- orders_o::getLastWashTimestampForPlate(reg_1) returns the created_at
  of the most recent non-deleted order that has at least one non-deleted
  order item, matching the contract used by
  customer_vehicles_o::getLastOrderByPlate().
- GET /numberplatescans now enriches each scan with a 'last_wash' key
  (MySQL DATETIME or null).
- New Pest test: tests/Unit/Orders/OrderLastWashTimestampForPlateTest.php
  asserts both the helper and the route wiring.
2026-08-17 14:20:07 +00:00

42 lines
2.0 KiB
PHP

<?php
it('orders_o exposes getLastWashTimestampForPlate that filters out orders without order items', function (): void {
$ordersFile = app_path('objects/orders_o.php');
expect(is_file($ordersFile))->toBeTrue();
$ordersCode = preg_replace('/\s+/', ' ', (string)file_get_contents($ordersFile));
expect($ordersCode)->toContain('public function getLastWashTimestampForPlate(string $reg_1): ?string');
// The helper must look at non-deleted orders with non-deleted order items,
// matching the contract used by customer_vehicles_o::getLastOrderByPlate().
expect($ordersCode)->toContain("'reg_1' => $normalized_reg_1");
expect($ordersCode)->toContain("'deleted_at' => null");
expect($ordersCode)->toContain("'order_id' => $order_id");
expect($ordersCode)->toContain('return $created_at;');
expect($ordersCode)->toContain('return null;');
});
it('plateScansRoute enriches GET /numberplatescans with last_wash per scan (TRU-78)', function (): void {
$routeFile = app_path('routes/plateScansRoute.php');
$ordersFile = app_path('objects/orders_o.php');
expect(is_file($routeFile))->toBeTrue();
expect(is_file($ordersFile))->toBeTrue();
$routeCode = preg_replace('/\s+/', ' ', (string)file_get_contents($routeFile));
$ordersCode = preg_replace('/\s+/', ' ', (string)file_get_contents($ordersFile));
// The route already loads orders_o and customer_vehicles_o; verify the
// new enrichment is wired in the GET /numberplatescans handler.
expect($routeCode)->toContain("\$this->get('/numberplatescans', function () {");
expect($routeCode)->toContain("'last_wash'");
expect($routeCode)->toContain('getLastWashTimestampForPlate');
expect($routeCode)->toContain("'last_wash' => (new orders_o())->getLastWashTimestampForPlate");
expect($routeCode)->toContain('$tmp_scan_last_wash');
// The helper definition must live in orders_o so the enrichment is real,
// not a stub.
expect($ordersCode)->toContain('public function getLastWashTimestampForPlate(string $reg_1): ?string');
});