Files
coolify/tests/v4/Browser/ScheduledTaskDeleteTest.php
T
Andras BacsaiandClaude Opus 5.5 a5acf81751 fix(scheduled-tasks): stop 404 after deleting a scheduled task
The executions list polled with the task stored as a model, so a poll
after the delete failed to load it and showed a 404. Load the task by id
on each request and skip the refresh when it is gone. Return true from
delete so the confirmation modal does not refresh the deleted task.

Closes #11814

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-16 00:32:13 +02:00

78 lines
2.7 KiB
PHP

<?php
use App\Models\ScheduledTask;
use Illuminate\Foundation\Testing\RefreshDatabase;
uses(RefreshDatabase::class);
beforeEach(function () {
$this->stack = seedBrowserResourceStack();
$service = createBrowserService($this->stack, ['uuid' => 'svc-browser-task', 'name' => 'Task Service'])['service'];
$this->task = ScheduledTask::factory()->create([
'team_id' => 0,
'service_id' => $service->id,
'name' => 'nightly-cleanup',
'command' => 'echo cleanup',
'frequency' => 'daily',
]);
$this->base = serviceConfigurationUrl($this->stack['project'], $this->stack['environment'], $service);
});
/**
* Records the HTTP status of every Livewire request the page sends.
*/
function recordScheduledTaskLivewireStatuses(mixed $page): void
{
$page->script(<<<'JS'
(() => {
window.livewireStatuses = [];
const fetch = window.fetch;
window.fetch = async (...args) => {
const response = await fetch(...args);
if (String(args[0]).includes('/livewire')) {
window.livewireStatuses.push(response.status);
}
return response;
};
})()
JS);
}
it('deletes a service scheduled task and returns to the task list', function () {
loginAndSkipBoarding();
$page = visit("{$this->base}/tasks/{$this->task->uuid}")
->assertSee('Task configuration');
recordScheduledTaskLivewireStatuses($page);
$page->click('button:visible:has-text("Delete")')
->fill('input[x-model="userConfirmationText"]', 'nightly-cleanup')
->click('button:visible:has-text("Permanently delete")')
->wait(3);
expect($this->task->fresh())->toBeNull()
->and($page->script('window.livewireStatuses'))->not->toContain(404);
$page->assertPathIs(parse_url("{$this->base}/scheduled-tasks", PHP_URL_PATH))
->screenshot(filename: 'scheduled-task-deleted');
});
it('keeps polling executions without a 404 after the task is deleted', function () {
loginAndSkipBoarding();
$page = visit("{$this->base}/tasks/{$this->task->uuid}")
->assertSee('Recent executions');
recordScheduledTaskLivewireStatuses($page);
// The executions list polls every 5 seconds, so a poll can run after the delete and before the list page loads.
$this->task->delete();
$page->script(<<<'JS'
Livewire.all().find((component) => component.name === 'project.shared.scheduled-task.executions')
.$wire.refreshExecutions()
JS);
$page->wait(1);
expect($page->script('window.livewireStatuses'))->toBe([200]);
$page->screenshot(filename: 'scheduled-task-poll-after-delete');
});