Add unit tests for legacy schema compatibility, property gate commands, lane state transitions, and relay synchronization. Extend relay logic with demo relay handling, dynamic image updates, phone normalization, and machine relay hard set methods.

This commit is contained in:
Jeppe Bundgaard
2026-03-26 11:11:34 +01:00
parent 76729f1b99
commit f148b39a85
22 changed files with 891 additions and 149 deletions
@@ -108,9 +108,7 @@ class selfserve_wash_flow implements selfserve_wash_flow_i
'task_ids' => array_map(static fn(array $task): int => (int)$task['id'], $snapshot['tasks']),
]);
if ($activateMachine && (bool)$snapshot['allowed']) {
$this->enableMachineRelayIfAllowed($snapshot, $session);
}
$this->syncMachineRelayFromVisibleServices($snapshot, $session, $activateMachine);
return $this->getSessionSummary((int)$session->id);
}
@@ -475,8 +473,6 @@ class selfserve_wash_flow implements selfserve_wash_flow_i
$laneId = (int)$snapshot['lane']['id'];
$lane = (new selfserve())->lane($laneId);
$lane->setLaneCache($laneId, $lane::CACHE_SELFSERVE_LANE_KEY_ALLOWED_SERVICES, $snapshot['allowed_services']);
$lane->turnOnRelay(selfserve_lane_relay::MACHINE);
$this->enableCleanerRelayForStartedWash($lane);
$session->markRelayEnabled();
@@ -488,6 +484,26 @@ class selfserve_wash_flow implements selfserve_wash_flow_i
]);
}
protected function syncMachineRelayFromVisibleServices(array $snapshot, selfserve_wash_sessions_o $session, bool $allowEnable): void
{
$laneId = (int)$snapshot['lane']['id'];
$lane = (new selfserve())->lane($laneId);
$sync = $lane->syncMachineRelayFromVisibleServices(
is_array($snapshot['allowed_services'] ?? null) ? $snapshot['allowed_services'] : [],
$allowEnable
);
if (($sync['relay_action'] ?? '') === 'enabled') {
$this->enableMachineRelayIfAllowed($snapshot, $session);
}
$relayTargetOn = (bool)($sync['relay_target_on'] ?? false);
if (!$relayTargetOn && (bool)$session->machine_relay_enabled->value() === true) {
$session->markRelayDisabled();
$session->updateStatus($this->deriveCurrentStatus($snapshot, $session));
}
}
protected function deriveBaseStatus(array $snapshot): selfserve_wash_session_status
{
if (!$snapshot['all_visible_questions_answered']) {
@@ -720,6 +736,7 @@ class selfserve_wash_flow implements selfserve_wash_flow_i
(string)$task['description'],
$task['services'],
$task['buttons'],
$task['dynamic_images_vehicle_type'] ?? null,
);
}
}
@@ -986,4 +1003,10 @@ class selfserve_wash_flow implements selfserve_wash_flow_i
}
return $normalized;
}
public function isMachineAllowedToStartWash(int $id): bool
{
$sessionSummary = $this->getSessionSummary($id);
return ($sessionSummary['session']['allowed'] ?? false) === true;
}
}