migrating tests (Application, Console and Cronjob)

This commit is contained in:
Saeed Vaziry
2024-10-08 22:15:50 +02:00
parent 974af959f1
commit 0da21f40bd
39 changed files with 254 additions and 2684 deletions

View File

@ -5,7 +5,10 @@
use App\Enums\CronjobStatus;
use App\Facades\SSH;
use App\Models\CronJob;
use App\Web\Pages\Servers\CronJobs\Index;
use App\Web\Pages\Servers\CronJobs\Widgets\CronJobsList;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Livewire;
use Tests\TestCase;
class CronjobTest extends TestCase
@ -21,7 +24,7 @@ public function test_see_cronjobs_list()
'server_id' => $this->server->id,
]);
$this->get(route('servers.cronjobs', $this->server))
$this->get(Index::getUrl(['server' => $this->server]))
->assertSuccessful()
->assertSeeText($cronjob->frequencyLabel());
}
@ -38,10 +41,11 @@ public function test_delete_cronjob()
'user' => 'vito',
]);
$this->delete(route('servers.cronjobs.destroy', [
Livewire::test(CronJobsList::class, [
'server' => $this->server,
'cronJob' => $cronjob,
]))->assertSessionDoesntHaveErrors();
])
->callTableAction('delete', $cronjob->id)
->assertSuccessful();
$this->assertDatabaseMissing('cron_jobs', [
'id' => $cronjob->id,
@ -57,11 +61,15 @@ public function test_create_cronjob()
$this->actingAs($this->user);
$this->post(route('servers.cronjobs.store', $this->server), [
'command' => 'ls -la',
'user' => 'vito',
'frequency' => '* * * * *',
])->assertSessionDoesntHaveErrors();
Livewire::test(Index::class, [
'server' => $this->server,
])
->callAction('create', [
'command' => 'ls -la',
'user' => 'vito',
'frequency' => '* * * * *',
])
->assertSuccessful();
$this->assertDatabaseHas('cron_jobs', [
'server_id' => $this->server->id,
@ -81,12 +89,16 @@ public function test_create_custom_cronjob()
$this->actingAs($this->user);
$this->post(route('servers.cronjobs.store', $this->server), [
'command' => 'ls -la',
'user' => 'vito',
'frequency' => 'custom',
'custom' => '* * * 1 1',
])->assertSessionDoesntHaveErrors();
Livewire::test(Index::class, [
'server' => $this->server,
])
->callAction('create', [
'command' => 'ls -la',
'user' => 'vito',
'frequency' => 'custom',
'custom' => '* * * 1 1',
])
->assertSuccessful();
$this->assertDatabaseHas('cron_jobs', [
'server_id' => $this->server->id,
@ -115,10 +127,12 @@ public function test_enable_cronjob()
'status' => CronjobStatus::DISABLED,
]);
$this->post(route('servers.cronjobs.enable', [
Livewire::test(CronJobsList::class, [
'server' => $this->server,
'cronJob' => $cronjob,
]))->assertSessionDoesntHaveErrors();
])
->assertTableActionHidden('disable', $cronjob->id)
->callTableAction('enable', $cronjob->id)
->assertSuccessful();
$cronjob->refresh();
@ -143,10 +157,12 @@ public function test_disable_cronjob()
'status' => CronjobStatus::READY,
]);
$this->post(route('servers.cronjobs.disable', [
Livewire::test(CronJobsList::class, [
'server' => $this->server,
'cronJob' => $cronjob,
]))->assertSessionDoesntHaveErrors();
])
->assertTableActionHidden('enable', $cronjob->id)
->callTableAction('disable', $cronjob->id)
->assertSuccessful();
$cronjob->refresh();