fix(api): log new order id when POST /orders succeeds (#374)
Merges api PR #374.
This commit is contained in:
@@ -237,7 +237,7 @@ class ordersRoute
|
|||||||
$order->setPendingHandheldIndicator();
|
$order->setPendingHandheldIndicator();
|
||||||
}
|
}
|
||||||
// Log the incident
|
// Log the incident
|
||||||
(new logs_o())->add('orders', $data['department_id'], 1, $user->id, 'ADD_ORDER', 'Successfully added an order (ID: ' . $data['department_id'] . ')');
|
(new logs_o())->add('orders', $data['department_id'], 1, $user->id, 'ADD_ORDER', 'Successfully added an order (ID: ' . (int)$order->id . ')');
|
||||||
// Return a success message, containing the orders array
|
// Return a success message, containing the orders array
|
||||||
$response->success($order->asArray());
|
$response->success($order->asArray());
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
it('logs the newly created order id (not the department id) when POST /orders succeeds', function (): void {
|
||||||
|
$routeFile = app_path('routes/ordersRoute.php');
|
||||||
|
$content = file_get_contents($routeFile);
|
||||||
|
|
||||||
|
expect($content)->not->toBeFalse();
|
||||||
|
|
||||||
|
// The POST /orders handler must log the id of the order that was just
|
||||||
|
// persisted by addArray(), not the department id from the request body.
|
||||||
|
// Without this, the audit trail for the "check-in creates 0-orders" bug
|
||||||
|
// is useless — every successful create logs the wrong identifier.
|
||||||
|
expect($content)->toContain("'Successfully added an order (ID: ' . (int)\$order->id . ')'");
|
||||||
|
|
||||||
|
// Guard against the previous copy/paste regression reappearing.
|
||||||
|
expect($content)->not->toContain("'Successfully added an order (ID: ' . \$data['department_id'] . ')'");
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user