Activate self-serve opening relays

This commit is contained in:
Jeppe Bundgaard
2026-07-09 11:26:03 +02:00
parent 6a00f023b1
commit b686e578f7
5 changed files with 346 additions and 9 deletions
@@ -0,0 +1,28 @@
<?php
it('registers an opening-time self-serve cleaner relay activation cron', function (): void {
$tasks = require app_path('modules/selfserve/cron/tasks.php');
expect($tasks)->toHaveCount(1);
expect($tasks[0]['id'])->toBe('selfserve.activate_opening_cleaner_relays');
expect($tasks[0]['legacy_name'])->toBe('SelfserveOpeningRelayActivationCron');
expect($tasks[0]['handler'])->toBe('SelfserveOpeningRelayActivationCron');
expect($tasks[0]['schedule'])->toBe(['type' => 'interval', 'seconds' => 60]);
});
it('activates only configured cleaner relays after department opening time', function (): void {
$cronContent = file_get_contents(app_path('cron/Cron.php'));
expect($cronContent)->not->toBeFalse();
expect($cronContent)->toContain('function SelfserveOpeningRelayActivationCron(): array');
expect($cronContent)->toContain("new DateTimeZone('Europe/Copenhagen')");
expect($cronContent)->toContain('department_time_bookings_opening_hours');
expect($cronContent)->toContain("dv.variable = 'selfserve_enabled'");
expect($cronContent)->toContain('dl.selfserve_enabled');
expect($cronContent)->toContain('relay_machine_cleaner_id');
expect($cronContent)->toContain('$nowSeconds >= $opensAtSeconds && $nowSeconds < $closesAtSeconds');
expect($cronContent)->toContain('setMachineCleanerRelayStatusHard(true)');
expect($cronContent)->toContain('selfserve:opening-cleaner-relays:');
expect($cronContent)->not->toContain('setMachineRelayStatusHard(true)');
expect($cronContent)->not->toContain('setMachineProgramPickerRelayStatusHard(true)');
});