Add tests for customer-scoped vehicle conditions and property gate permissions
- Introduced tests for `SelfserveNonOwnedVehicleWashAccess` to validate customer-scoped conditions for non-owned vehicles. - Added `SelfservePropertyGatePermissionBypassTest` to ensure proper permission handling for lanes and departments. - Updated `department_selfserve_vehicle_conditions_o` and routes to prevent cross-customer answer persistence. - Enhanced `selfserve_wash_flow` with customer-scoped persisted answer logic and improved method parameters for vehicle eligibility and session synchronization. - Adjusted OpenAPI spec and unit tests to reflect new customer-scoping behavior in self-serve operations.
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
app_require('routes/moduleSelfServeRoute.php');
|
||||
app_require('modules/selfserve/classes/selfserve_lane.php');
|
||||
app_require('objects/department_lanes_o.php');
|
||||
app_require('classes/object_property.php');
|
||||
|
||||
use classes\object_property;
|
||||
use modules\selfserve\classes\selfserve_lane;
|
||||
use objects\department_lanes_o;
|
||||
use routes\moduleSelfServeRoute;
|
||||
|
||||
class SelfservePropertyGatePermissionBypassRouteHarness extends moduleSelfServeRoute
|
||||
{
|
||||
public bool $activeWashResult = false;
|
||||
/** @var array<int,array{department_id:int,customer_number:int}> */
|
||||
public array $activeWashChecks = [];
|
||||
|
||||
public function canUsePropertyGate(selfserve_lane $lane, int $customer_number): bool
|
||||
{
|
||||
return $this->canCustomerUsePropertyGateForLane($lane, $customer_number);
|
||||
}
|
||||
|
||||
protected function customerHasActiveSelfServeWashInDepartment(int $department_id, int $customer_number): bool
|
||||
{
|
||||
$this->activeWashChecks[] = [
|
||||
'department_id' => $department_id,
|
||||
'customer_number' => $customer_number,
|
||||
];
|
||||
|
||||
return $this->activeWashResult;
|
||||
}
|
||||
}
|
||||
|
||||
class SelfservePropertyGatePermissionBypassDepartmentLaneFake extends department_lanes_o
|
||||
{
|
||||
public function __construct(int $department_id)
|
||||
{
|
||||
$this->id = -1;
|
||||
$this->department = new object_property('department_lanes', -1, 'department', 'int');
|
||||
$this->department->set($department_id);
|
||||
}
|
||||
|
||||
public function structure(): void
|
||||
{
|
||||
// Skip database bootstrap for this unit test.
|
||||
}
|
||||
}
|
||||
|
||||
function selfserve_property_gate_permission_lane_for_department(int $department_id): selfserve_lane
|
||||
{
|
||||
$reflection = new ReflectionClass(selfserve_lane::class);
|
||||
/** @var selfserve_lane $lane */
|
||||
$lane = $reflection->newInstanceWithoutConstructor();
|
||||
$lane->id = 77;
|
||||
$lane->department_lane = new SelfservePropertyGatePermissionBypassDepartmentLaneFake($department_id);
|
||||
|
||||
return $lane;
|
||||
}
|
||||
|
||||
it('allows property gate commands for customers with an active wash in the target department', function (): void {
|
||||
$route = new SelfservePropertyGatePermissionBypassRouteHarness();
|
||||
$route->activeWashResult = true;
|
||||
$lane = selfserve_property_gate_permission_lane_for_department(6);
|
||||
|
||||
expect($route->canUsePropertyGate($lane, 12345679))->toBeTrue();
|
||||
expect($route->activeWashChecks)->toBe([
|
||||
[
|
||||
'department_id' => 6,
|
||||
'customer_number' => 12345679,
|
||||
],
|
||||
]);
|
||||
});
|
||||
|
||||
it('does not bypass property gate permissions without a positive customer number', function (): void {
|
||||
$route = new SelfservePropertyGatePermissionBypassRouteHarness();
|
||||
$route->activeWashResult = true;
|
||||
$lane = selfserve_property_gate_permission_lane_for_department(6);
|
||||
|
||||
expect($route->canUsePropertyGate($lane, 0))->toBeFalse();
|
||||
expect($route->activeWashChecks)->toBe([]);
|
||||
});
|
||||
|
||||
it('does not bypass property gate permissions when the customer has no active wash in the target department', function (): void {
|
||||
$route = new SelfservePropertyGatePermissionBypassRouteHarness();
|
||||
$route->activeWashResult = false;
|
||||
$lane = selfserve_property_gate_permission_lane_for_department(6);
|
||||
|
||||
expect($route->canUsePropertyGate($lane, 12345679))->toBeFalse();
|
||||
expect($route->activeWashChecks)->toBe([
|
||||
[
|
||||
'department_id' => 6,
|
||||
'customer_number' => 12345679,
|
||||
],
|
||||
]);
|
||||
});
|
||||
Reference in New Issue
Block a user