Resolve MyWash services from published config
This commit is contained in:
@@ -8,6 +8,7 @@ use classes\response;
|
||||
use classes\router;
|
||||
use classes\selfserve;
|
||||
use classes\stripe;
|
||||
use modules\selfserve\classes\selfserve_config_versioning;
|
||||
use modules\selfserve\classes\selfserve_lane;
|
||||
use modules\selfserve\classes\selfserve_wash_flow;
|
||||
use modules\selfserve\helpers\selfserve_lane_command;
|
||||
@@ -662,6 +663,7 @@ class moduleSelfServeRoute
|
||||
}
|
||||
|
||||
$allowed_services = [];
|
||||
$published_config_task_services = $this->publishedConfigTaskServicesForLane($lane, $task_ids);
|
||||
$merge_services = static function (array $services) use (&$allowed_services): void {
|
||||
foreach ($services as $srv) {
|
||||
$name = strtoupper((string)$srv);
|
||||
@@ -676,6 +678,10 @@ class moduleSelfServeRoute
|
||||
$merge_services($session_task_services[$tid]);
|
||||
continue;
|
||||
}
|
||||
if (array_key_exists($tid, $published_config_task_services)) {
|
||||
$merge_services($published_config_task_services[$tid]);
|
||||
continue;
|
||||
}
|
||||
|
||||
$t = new \objects\department_selfserve_tasks_o();
|
||||
$t->select($tid);
|
||||
@@ -1936,6 +1942,59 @@ class moduleSelfServeRoute
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int,int> $task_ids
|
||||
* @return array<int,array<int,string>>
|
||||
*/
|
||||
private function publishedConfigTaskServicesForLane(selfserve_lane $lane, array $task_ids): array
|
||||
{
|
||||
$department_id = $this->departmentIdForLane($lane);
|
||||
if ($department_id <= 0 || $task_ids === []) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$published = (new selfserve_config_versioning())->getPublishedConfig($department_id);
|
||||
$config = is_array($published) ? (array)($published['config'] ?? []) : [];
|
||||
$tasks = is_array($config['tasks'] ?? null) ? $config['tasks'] : [];
|
||||
if ($tasks === []) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$requested_task_ids = array_fill_keys(array_map(static fn($task_id): int => (int)$task_id, $task_ids), true);
|
||||
$services_by_task_id = [];
|
||||
foreach ($tasks as $task) {
|
||||
if (!is_array($task)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$task_id = (int)($task['id'] ?? $task['task_id'] ?? 0);
|
||||
if ($task_id <= 0 || !isset($requested_task_ids[$task_id])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$task_department_id = (int)($task['department'] ?? $task['department_id'] ?? 0);
|
||||
if ($task_department_id !== 0 && $task_department_id !== $department_id) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$task_lane_id = (int)($task['lane'] ?? $task['lane_id'] ?? 0);
|
||||
if ($task_lane_id !== 0 && $task_lane_id !== (int)$lane->id) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$services = $task['services'] ?? [];
|
||||
if (is_string($services)) {
|
||||
$decoded = json_decode($services, true);
|
||||
$services = json_last_error() === JSON_ERROR_NONE && is_array($decoded) ? $decoded : [];
|
||||
}
|
||||
|
||||
$services_by_task_id[$task_id] = is_array($services) ? $services : [];
|
||||
}
|
||||
|
||||
return $services_by_task_id;
|
||||
}
|
||||
|
||||
private function requestedShellyTransportOverride(): ?string
|
||||
{
|
||||
$transport = null;
|
||||
|
||||
@@ -196,6 +196,72 @@ it('derives allowed services from v2 session task snapshots when task rows are n
|
||||
}
|
||||
});
|
||||
|
||||
it('derives allowed services from published v2 config task snapshots when no session exists yet', function (): void {
|
||||
$group = api_fixtures()->createGroup([], [
|
||||
'list_own_department_selfserve_vehicle_conditions',
|
||||
]);
|
||||
$scenario = api_fixtures()->createSelfServeScenario([
|
||||
'customer' => ['group_id' => $group['id']],
|
||||
'department_selfserve_enabled' => true,
|
||||
'lane_selfserve_enabled' => true,
|
||||
'session' => [
|
||||
'status' => 'COMPLETED',
|
||||
'completed_at' => date('Y-m-d H:i:s'),
|
||||
'wash_started_at' => date('Y-m-d H:i:s'),
|
||||
],
|
||||
]);
|
||||
$headers = api_fixtures()->bearerHeaders(
|
||||
api_fixtures()->createAuthToken((int)$scenario['customer']['id'])
|
||||
);
|
||||
$laneId = (int)$scenario['lane']['id'];
|
||||
$departmentId = (int)$scenario['department']['id'];
|
||||
$productId = (int)$scenario['product']['id'];
|
||||
$v2TaskId = 910000 + $laneId;
|
||||
|
||||
$configVersion = (new \objects\selfserve_config_versions_o())->add(
|
||||
$departmentId,
|
||||
\modules\selfserve\classes\selfserve_config_versioning::STATUS_PUBLISHED,
|
||||
1,
|
||||
[
|
||||
'schema_version' => 2,
|
||||
'tasks' => [
|
||||
[
|
||||
'id' => $v2TaskId,
|
||||
'department' => $departmentId,
|
||||
'lane' => $laneId,
|
||||
'product' => $productId,
|
||||
'machine_type_id' => 0,
|
||||
'task' => 'Published v2 machine task',
|
||||
'description' => 'Task exists only in the published config snapshot.',
|
||||
'order_priority' => 10,
|
||||
'services' => ['MACHINE', 'PROGRAM_PICKER'],
|
||||
],
|
||||
],
|
||||
],
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
date('Y-m-d H:i:s'),
|
||||
);
|
||||
|
||||
try {
|
||||
$response = api_client()
|
||||
->post('/modules/self-serve/lane/services/allowed', [
|
||||
'lane_id' => $laneId,
|
||||
'task_ids' => [$v2TaskId],
|
||||
], $headers)
|
||||
->assertStatus(200)
|
||||
->assertSuccess(true);
|
||||
|
||||
expect($response->data()['allowed_services'] ?? [])->toBe([
|
||||
'MACHINE',
|
||||
'PROGRAM_PICKER',
|
||||
]);
|
||||
} finally {
|
||||
$configVersion->delete();
|
||||
}
|
||||
});
|
||||
|
||||
it('keeps long generated task descriptions when refreshing vehicle eligibility snapshots', function (): void {
|
||||
$group = api_fixtures()->createGroup([], [
|
||||
'list_own_department_selfserve_vehicle_conditions',
|
||||
|
||||
@@ -259,6 +259,8 @@ it('wires allowed services route through machine relay visibility sync', functio
|
||||
expect($moduleSelfServeRoute)->toContain('selfserve_wash_session_tasks_o');
|
||||
expect($moduleSelfServeRoute)->toContain('selectLatestOpenByLane');
|
||||
expect($moduleSelfServeRoute)->toContain('$session_task_services[$task_id]');
|
||||
expect($moduleSelfServeRoute)->toContain('publishedConfigTaskServicesForLane');
|
||||
expect($moduleSelfServeRoute)->toContain('$published_config_task_services[$tid]');
|
||||
expect($moduleSelfServeRoute)->toContain('setAllowedServicesFromVisibleTasks($allowed_services)');
|
||||
expect($moduleSelfServeRoute)->not->toContain('syncMachineRelayFromVisibleServices($allowed_services, true)');
|
||||
expect($moduleSelfServeRoute)->toContain("'relay_sync' => \$relay_sync");
|
||||
|
||||
Reference in New Issue
Block a user