Files
api/services/nginx/app/tests/Unit/Selfserve/SelfserveStartCleanerRelayWiringTest.php
T
Jeppe Bundgaard 54de2e5674 Add fake classes for relay logic and refactor relay shutdown without pre-checking status
Introduce helper classes `SelfserveWashCompletionRelayValueFake`, `SelfserveWashCompletionDepartmentLaneFake`, `SelfserveWashCompletionRelayLaneFake`, and `SelfserveWashCompletionFlowHarness` to simulate relay logic for unit tests. Refactor `turnOffRelayIfConfiguredAndOn` to `turnOffRelayIfConfigured`, removing relay status pre-check for cleaner and machine relays when completing a wash session, and test associated relay actions.
2026-05-27 19:30:31 +02:00

37 lines
2.1 KiB
PHP

<?php
it('enables cleaner relay on wash start command and webhook flow', function (): void {
$commandTrait = file_get_contents(app_path('modules/selfserve/traits/selfserve_lane_command_t.php'));
$washFlow = file_get_contents(app_path('modules/selfserve/classes/selfserve_wash_flow.php'));
expect($commandTrait)->not->toBeFalse();
expect($commandTrait)->toContain('turnOnCleanerRelayForWashStart()');
expect($commandTrait)->toContain('setMachineCleanerRelayStatusHard(true)');
expect($washFlow)->not->toBeFalse();
expect($washFlow)->toContain('enableCleanerRelayForStartedWash(');
expect($washFlow)->toContain('setMachineCleanerRelayStatusHard(true)');
});
it('keeps cleaner relay enable wired into machine relay start paths', function (): void {
$washFlow = file_get_contents(app_path('modules/selfserve/classes/selfserve_wash_flow.php'));
$moduleRoute = file_get_contents(app_path('routes/moduleSelfServeRoute.php'));
expect($washFlow)->not->toBeFalse();
$enableMachineRelayMethodOffset = strpos($washFlow, 'protected function enableMachineRelayIfAllowed');
expect($enableMachineRelayMethodOffset)->not->toBeFalse();
$enableMachineRelayMethod = substr($washFlow, (int)$enableMachineRelayMethodOffset, 1200);
expect($enableMachineRelayMethod)->toContain('$this->enableCleanerRelayForStartedWash($lane);');
$cleanerEnableOffset = strpos($enableMachineRelayMethod, '$this->enableCleanerRelayForStartedWash($lane);');
$alreadyEnabledGuardOffset = strpos($enableMachineRelayMethod, 'if ((bool)$session->machine_relay_enabled->value() === true)');
expect($cleanerEnableOffset)->not->toBeFalse()
->and($alreadyEnabledGuardOffset)->not->toBeFalse()
->and($cleanerEnableOffset)->toBeLessThan($alreadyEnabledGuardOffset);
expect($moduleRoute)->not->toBeFalse();
$machineEnableRouteOffset = strpos($moduleRoute, '/modules/self-serve/lane/relay/machine/enable');
expect($machineEnableRouteOffset)->not->toBeFalse();
$machineEnableRoute = substr($moduleRoute, (int)$machineEnableRouteOffset, 1800);
expect($machineEnableRoute)->toContain('$lane->setMachineCleanerRelayStatusHard(true);');
});