Files
api/services/nginx/app/tests/Unit/Selfserve/SelfserveRouteWiringTest.php
T
Jeppe Bundgaard feb9aac4f7 Handle relay command job timeouts for edge gateways
- Introduce `expireTimedOutRelayStatusCommandJobs` to clean up long-pending relay status command jobs.
- Add `TIMED_OUT` status for relay command jobs and incorporate it into job status evaluations.
- Refactor command job finalization to support timeout-specific error messaging.
- Improve handling of fast-path failures in edge broker commands.
2026-04-27 16:47:09 +02:00

190 lines
12 KiB
PHP

<?php
it('wires self-serve machine types, eligibility, summaries, and machine-start webhook routes', function (): void {
$machineTypesRoute = file_get_contents(app_path('routes/departmentSelfserveMachineTypesRoute.php'));
$vehicleConditionsRoute = file_get_contents(app_path('routes/departmentSelfserveVehicleConditionsRoute.php'));
$webhookRoute = file_get_contents(app_path('routes/machineButtonPressRoute.php'));
expect($machineTypesRoute)->not->toBeFalse();
expect($machineTypesRoute)->toContain('/department/selfserve/machine-types');
expect($vehicleConditionsRoute)->not->toBeFalse();
expect($vehicleConditionsRoute)->toContain('/department/selfserve/vehicle/allowed');
expect($vehicleConditionsRoute)->toContain('/department/selfserve/washes/summary');
expect($vehicleConditionsRoute)->toContain('synchronizeSession');
expect($webhookRoute)->not->toBeFalse();
expect($webhookRoute)->toContain('/relay/button/press/post');
expect($webhookRoute)->toContain('recordMachineStartWebhook');
});
it('keeps machine type support wired into lanes, tasks, and conditions routes', function (): void {
$lanesRoute = file_get_contents(app_path('routes/departmentLanesRoute.php'));
$tasksRoute = file_get_contents(app_path('routes/departmentSelfserveTasksRoute.php'));
$conditionsRoute = file_get_contents(app_path('routes/departmentSelfserveConditionsRoute.php'));
$questionsRoute = file_get_contents(app_path('routes/departmentSelfserveQuestionsRoute.php'));
expect($lanesRoute)->toContain('machine_type_id');
expect($tasksRoute)->toContain('machine_type_id');
expect($conditionsRoute)->toContain('machine_type_id');
expect($questionsRoute)->toContain('department') // shared questions still use the legacy columns with default 0 scope
->toContain('lane')
->toContain('product');
});
it('wires self-serve config draft/publish/rollback lifecycle endpoints', function (): void {
$configRoute = file_get_contents(app_path('routes/departmentSelfserveConfigVersionsRoute.php'));
expect($configRoute)->not->toBeFalse();
expect($configRoute)->toContain('/department/selfserve/config/versions');
expect($configRoute)->toContain('/department/selfserve/config/history');
expect($configRoute)->toContain('/department/selfserve/config/active');
expect($configRoute)->toContain('/department/selfserve/config/draft');
expect($configRoute)->toContain('/department/selfserve/config/validate');
expect($configRoute)->toContain('/department/selfserve/config/publish');
expect($configRoute)->toContain('/department/selfserve/config/rollback');
expect($configRoute)->toContain('publish_department_selfserve_config_versions');
expect($configRoute)->toContain('rollback_department_selfserve_config_versions');
});
it('wires machine wash included minutes into self-serve module config', function (): void {
$selfserveConfig = file_get_contents(app_path('modules/selfserve/selfserve_c.php'));
expect($selfserveConfig)->not->toBeFalse();
expect($selfserveConfig)->toContain('selfserve_machine_wash_minutes_included_c');
expect($selfserveConfig)->toContain('machine_wash_minutes_included');
});
it('keeps legacy self-serve CRUD routes syncing canonical drafts', function (): void {
$questionsRoute = file_get_contents(app_path('routes/departmentSelfserveQuestionsRoute.php'));
$conditionsRoute = file_get_contents(app_path('routes/departmentSelfserveConditionsRoute.php'));
$rulesRoute = file_get_contents(app_path('routes/departmentSelfserveConditionRulesRoute.php'));
$tasksRoute = file_get_contents(app_path('routes/departmentSelfserveTasksRoute.php'));
expect($questionsRoute)->toContain('syncDraftFromLegacyForDepartment');
expect($conditionsRoute)->toContain('syncDraftFromLegacyForDepartment');
expect($rulesRoute)->toContain('syncDraftFromLegacyForDepartment');
expect($tasksRoute)->toContain('syncDraftFromLegacyForDepartment');
});
it('wires machine relay status get and set endpoints', function (): void {
$moduleSelfServeRoute = file_get_contents(app_path('routes/moduleSelfServeRoute.php'));
expect($moduleSelfServeRoute)->not->toBeFalse();
expect($moduleSelfServeRoute)->toContain('/modules/self-serve/lane/relay/machine/status');
expect($moduleSelfServeRoute)->toContain('/modules/self-serve/lane/relay/machine/set');
expect($moduleSelfServeRoute)->toContain('/modules/self-serve/lane/relay/machine_program_picker/status');
expect($moduleSelfServeRoute)->toContain('/modules/self-serve/lane/relay/machine_program_picker/set');
expect($moduleSelfServeRoute)->toContain('/modules/self-serve/lane/relay/machine_cleaner/status');
expect($moduleSelfServeRoute)->toContain('/modules/self-serve/lane/relay/machine_cleaner/set');
expect($moduleSelfServeRoute)->toContain('getMachineRelayStatus');
expect($moduleSelfServeRoute)->toContain('setMachineRelayStatus');
expect($moduleSelfServeRoute)->toContain('getMachineProgramPickerRelayStatus');
expect($moduleSelfServeRoute)->toContain('setMachineProgramPickerRelayStatus');
expect($moduleSelfServeRoute)->toContain('getMachineCleanerRelayStatus');
expect($moduleSelfServeRoute)->toContain('setMachineCleanerRelayStatus');
expect($moduleSelfServeRoute)->toContain('setMachineCleanerRelayStatusHard(true)');
expect($moduleSelfServeRoute)->toContain('applyShellyTransportOverride($lane)');
expect($moduleSelfServeRoute)->toContain("'transport' => \$this->requestedShellyTransportOverride()");
expect($moduleSelfServeRoute)->toContain('buildRelayStatusResponse');
});
it('applies Shelly transport overrides across self-serve relay side-effect routes', function (): void {
$moduleSelfServeRoute = file_get_contents(app_path('routes/moduleSelfServeRoute.php'));
expect($moduleSelfServeRoute)->not->toBeFalse();
expect(substr_count($moduleSelfServeRoute, 'applyShellyTransportOverride($lane)'))->toBeGreaterThanOrEqual(17);
expect($moduleSelfServeRoute)->toContain('$lane->execute($command, $args);');
expect($moduleSelfServeRoute)->toContain('$lane->syncMachineRelayFromVisibleServices($allowed_services, true);');
expect($moduleSelfServeRoute)->toContain('$lane->open($gate);');
expect($moduleSelfServeRoute)->toContain('$lane->turnOnRelay(selfserve_lane_relay::MACHINE, $duration);');
expect($moduleSelfServeRoute)->toContain('$lane->turnOnRelay(selfserve_lane_relay::MACHINE_PROGRAM_PICKER, $duration);');
expect($moduleSelfServeRoute)->toContain('$lane->turnOnRelay(selfserve_lane_relay::MACHINE_CLEANER, $duration);');
expect($moduleSelfServeRoute)->toContain('$lane->forceTurnOnMachineRelay($duration);');
expect($moduleSelfServeRoute)->toContain('$lane->forceTurnOffMachineRelay();');
expect($moduleSelfServeRoute)->toContain('$lane->forceTurnOnRelay(selfserve_lane_relay::MACHINE_PROGRAM_PICKER, $duration);');
expect($moduleSelfServeRoute)->toContain('$lane->forceTurnOffRelay(selfserve_lane_relay::MACHINE_PROGRAM_PICKER);');
expect($moduleSelfServeRoute)->toContain('$lane->forceTurnOnRelay(selfserve_lane_relay::MACHINE_CLEANER, $duration);');
expect($moduleSelfServeRoute)->toContain('$lane->forceTurnOffRelay(selfserve_lane_relay::MACHINE_CLEANER);');
});
it('wires allowed services route through machine relay visibility sync', function (): void {
$moduleSelfServeRoute = file_get_contents(app_path('routes/moduleSelfServeRoute.php'));
expect($moduleSelfServeRoute)->not->toBeFalse();
expect($moduleSelfServeRoute)->toContain('/modules/self-serve/lane/services/allowed');
expect($moduleSelfServeRoute)->toContain('syncMachineRelayFromVisibleServices($allowed_services, true)');
expect($moduleSelfServeRoute)->toContain("'relay_sync' => \$relay_sync");
});
it('wires self-serve lane gate open endpoint', function (): void {
$moduleSelfServeRoute = file_get_contents(app_path('routes/moduleSelfServeRoute.php'));
expect($moduleSelfServeRoute)->not->toBeFalse();
expect($moduleSelfServeRoute)->toContain('/modules/self-serve/lane/gate/open');
expect($moduleSelfServeRoute)->toContain('modules_selfserve_lane_gate_open');
expect($moduleSelfServeRoute)->toContain('selfserve_lane_port::ENTRANCE');
expect($moduleSelfServeRoute)->toContain('selfserve_lane_port::EXIT');
expect($moduleSelfServeRoute)->toContain('$lane->open($gate)');
expect($moduleSelfServeRoute)->toContain('Failed to open self-serve lane gate');
expect($moduleSelfServeRoute)->toContain("'Failed to open ' . strtolower(\$gate->name) . ' gate.'");
expect($moduleSelfServeRoute)->not->toContain('Failed to open lane gate: ');
});
it('wires self-serve property gate command permissions', function (): void {
$moduleSelfServeRoute = file_get_contents(app_path('routes/moduleSelfServeRoute.php'));
$commandTrait = file_get_contents(app_path('modules/selfserve/traits/selfserve_lane_command_t.php'));
expect($moduleSelfServeRoute)->not->toBeFalse();
expect($moduleSelfServeRoute)->toContain('case selfserve_lane_command::OPEN_PROPERTY_ACCESS_GATE');
expect($moduleSelfServeRoute)->toContain('case selfserve_lane_command::OPEN_PROPERTY_EXIT_GATE');
expect($moduleSelfServeRoute)->toContain('modules_selfserve_lane_command_execute_open_property_access_gate');
expect($moduleSelfServeRoute)->toContain('modules_selfserve_lane_command_execute_open_property_exit_gate');
expect($moduleSelfServeRoute)->toContain('Failed to execute self-serve property gate command');
expect($commandTrait)->not->toBeFalse();
expect($commandTrait)->toContain('Failed to open property access gate.');
expect($commandTrait)->toContain('Failed to open property exit gate.');
expect($commandTrait)->not->toContain('Failed to open property access gate: ');
});
it('wires in-progress self-serve wash details endpoint', function (): void {
$moduleSelfServeRoute = file_get_contents(app_path('routes/moduleSelfServeRoute.php'));
expect($moduleSelfServeRoute)->not->toBeFalse();
expect($moduleSelfServeRoute)->toContain('/modules/self-serve/lane/wash/in-progress');
expect($moduleSelfServeRoute)->toContain('modules_selfserve_lane_wash_in_progress_view');
expect($moduleSelfServeRoute)->toContain("'in_progress' => true");
expect($moduleSelfServeRoute)->toContain("'in_progress' => false");
expect($moduleSelfServeRoute)->toContain('selfserve_lane_status::OCCUPIED');
expect($moduleSelfServeRoute)->toContain('selfserve_lane_state::IN_WASH');
expect($moduleSelfServeRoute)->toContain('getWashStartTime');
expect($moduleSelfServeRoute)->toContain('machine_wash_minutes_included');
expect($moduleSelfServeRoute)->toContain("'included_minutes' =>");
expect($moduleSelfServeRoute)->toContain("'machine_relay_enabled' =>");
expect($moduleSelfServeRoute)->toContain("'machine_relay_enabled_at' =>");
expect($moduleSelfServeRoute)->toContain("'wash_started_at' =>");
});
it('wires vehicle type override into self-serve preview and synchronization routes', function (): void {
$vehicleConditionsRoute = file_get_contents(app_path('routes/departmentSelfserveVehicleConditionsRoute.php'));
$washFlow = file_get_contents(app_path('modules/selfserve/classes/selfserve_wash_flow.php'));
expect($vehicleConditionsRoute)->not->toBeFalse();
expect($vehicleConditionsRoute)->toContain('vehicle_type_id');
expect($vehicleConditionsRoute)->toContain('vehicle_type');
expect($vehicleConditionsRoute)->toContain('resolveVehicleTypeIdFromQuery');
expect($vehicleConditionsRoute)->toContain('resolveVehicleTypeIdFromRequest');
expect($vehicleConditionsRoute)->toContain('normalizeVehicleTypeOverride');
expect($vehicleConditionsRoute)->toContain('shouldRefreshSummaryForVehicleType');
expect($vehicleConditionsRoute)->toContain('previewVehicleEligibility($lane_id, $reg, $customer_number, $vehicle_type_id)');
expect($vehicleConditionsRoute)->toContain('synchronizeSession($lane_id, $reg, $customer_number, false, $vehicle_type_id)');
expect($vehicleConditionsRoute)->toContain('synchronizeSession($lane, $reg, $customer_id, true, $vehicle_type_id)');
expect($washFlow)->not->toBeFalse();
expect($washFlow)->toContain('resolveVehicleTypeId($vehicle, $vehicleTypeIdOverride)');
expect($washFlow)->toContain("'vehicle_type_id' => \$snapshot['vehicle_type_id']");
expect($washFlow)->toContain("\$session->vehicle_type_id->set(\$snapshot['vehicle_type_id']);");
expect($washFlow)->toContain("\$session->vehicle_id->set(\$snapshot['vehicle']['id'] ?? null);");
});