mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-02 14:36:17 +00:00
migrating tests (Application, Console and Cronjob)
This commit is contained in:
@ -5,8 +5,11 @@
|
||||
use App\Enums\DeploymentStatus;
|
||||
use App\Facades\SSH;
|
||||
use App\Models\GitHook;
|
||||
use App\Web\Pages\Servers\Sites\View;
|
||||
use App\Web\Pages\Servers\Sites\Widgets\DeploymentsList;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ApplicationTest extends TestCase
|
||||
@ -18,28 +21,29 @@ public function test_visit_application()
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$this->get(
|
||||
route('servers.sites.show', [
|
||||
View::getUrl([
|
||||
'server' => $this->server,
|
||||
'site' => $this->site,
|
||||
])
|
||||
)
|
||||
->assertSuccessful()
|
||||
->assertSee($this->site->domain);
|
||||
->assertSee($this->site->domain)
|
||||
->assertSee('Deployments')
|
||||
->assertSee('Actions');
|
||||
}
|
||||
|
||||
public function test_update_deployment_script()
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$this->post(
|
||||
route('servers.sites.application.deployment-script', [
|
||||
'server' => $this->server,
|
||||
'site' => $this->site,
|
||||
]),
|
||||
[
|
||||
Livewire::test(View::class, [
|
||||
'server' => $this->server,
|
||||
'site' => $this->site,
|
||||
])
|
||||
->callAction('deployment-script', [
|
||||
'script' => 'some script',
|
||||
]
|
||||
)->assertSessionDoesntHaveErrors();
|
||||
])
|
||||
->assertSuccessful();
|
||||
|
||||
$this->assertDatabaseHas('deployment_scripts', [
|
||||
'site_id' => $this->site->id,
|
||||
@ -59,7 +63,7 @@ public function test_deploy(): void
|
||||
'email' => 'test@example.com',
|
||||
'url' => 'https://github.com/commit-url',
|
||||
],
|
||||
], 200),
|
||||
]),
|
||||
]);
|
||||
|
||||
$this->site->deploymentScript->update([
|
||||
@ -68,13 +72,13 @@ public function test_deploy(): void
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$response = $this->post(route('servers.sites.application.deploy', [
|
||||
Livewire::test(View::class, [
|
||||
'server' => $this->server,
|
||||
'site' => $this->site,
|
||||
]))->assertSessionDoesntHaveErrors();
|
||||
|
||||
$response->assertSessionHas('toast.type', 'success');
|
||||
$response->assertSessionHas('toast.message', 'Deployment started!');
|
||||
])
|
||||
->callAction('deploy')
|
||||
->assertSuccessful()
|
||||
->assertNotified('Deployment started!');
|
||||
|
||||
$this->assertDatabaseHas('deployments', [
|
||||
'site_id' => $this->site->id,
|
||||
@ -84,22 +88,23 @@ public function test_deploy(): void
|
||||
SSH::assertExecutedContains('cd /home/vito/'.$this->site->domain);
|
||||
SSH::assertExecutedContains('git pull');
|
||||
|
||||
$this->get(route('servers.sites.show', [
|
||||
'server' => $this->server,
|
||||
'site' => $this->site,
|
||||
]))
|
||||
$this->get(
|
||||
View::getUrl([
|
||||
'server' => $this->server,
|
||||
'site' => $this->site,
|
||||
])
|
||||
)
|
||||
->assertSuccessful()
|
||||
->assertSee('test commit message');
|
||||
|
||||
$deployment = $this->site->deployments()->first();
|
||||
|
||||
$this->get(route('servers.sites.application.deployment.log', [
|
||||
Livewire::test(DeploymentsList::class, [
|
||||
'server' => $this->server,
|
||||
'site' => $this->site,
|
||||
'deployment' => $deployment,
|
||||
]))
|
||||
->assertRedirect()
|
||||
->assertSessionHas('content', 'fake output');
|
||||
])
|
||||
->callTableAction('view', $deployment->id)
|
||||
->assertSuccessful();
|
||||
}
|
||||
|
||||
public function test_change_branch()
|
||||
@ -108,14 +113,15 @@ public function test_change_branch()
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$this->post(route('servers.sites.application.branch', [
|
||||
Livewire::test(View::class, [
|
||||
'server' => $this->server,
|
||||
'site' => $this->site,
|
||||
]), [
|
||||
'branch' => 'master',
|
||||
])
|
||||
->assertSessionDoesntHaveErrors()
|
||||
->assertSessionHas('toast.type', 'success');
|
||||
->callAction('branch', [
|
||||
'branch' => 'master',
|
||||
])
|
||||
->assertSuccessful()
|
||||
->assertNotified('Branch updated!');
|
||||
|
||||
$this->site->refresh();
|
||||
$this->assertEquals('master', $this->site->branch);
|
||||
@ -128,15 +134,18 @@ public function test_enable_auto_deployment()
|
||||
Http::fake([
|
||||
'github.com/*' => Http::response([
|
||||
'id' => '123',
|
||||
], 200),
|
||||
], 201),
|
||||
]);
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$this->post(route('servers.sites.application.auto-deployment', [
|
||||
Livewire::test(View::class, [
|
||||
'server' => $this->server,
|
||||
'site' => $this->site,
|
||||
]))->assertSessionDoesntHaveErrors();
|
||||
])
|
||||
->callAction('auto-deployment')
|
||||
->assertSuccessful()
|
||||
->assertNotified('Auto deployment enabled!');
|
||||
|
||||
$this->site->refresh();
|
||||
|
||||
@ -154,15 +163,18 @@ public function test_disable_auto_deployment()
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$hook = GitHook::factory()->create([
|
||||
GitHook::factory()->create([
|
||||
'site_id' => $this->site->id,
|
||||
'source_control_id' => $this->site->source_control_id,
|
||||
]);
|
||||
|
||||
$this->delete(route('servers.sites.application.auto-deployment', [
|
||||
Livewire::test(View::class, [
|
||||
'server' => $this->server,
|
||||
'site' => $this->site,
|
||||
]))->assertSessionDoesntHaveErrors();
|
||||
])
|
||||
->callAction('auto-deployment')
|
||||
->assertSuccessful()
|
||||
->assertNotified('Auto deployment disabled!');
|
||||
|
||||
$this->site->refresh();
|
||||
|
||||
@ -175,12 +187,15 @@ public function test_update_env_file(): void
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$this->post(route('servers.sites.application.env', [
|
||||
Livewire::test(View::class, [
|
||||
'server' => $this->server,
|
||||
'site' => $this->site,
|
||||
]), [
|
||||
'env' => 'APP_ENV="production"',
|
||||
])->assertSessionDoesntHaveErrors();
|
||||
])
|
||||
->callAction('dot-env', [
|
||||
'env' => 'APP_ENV="production"',
|
||||
])
|
||||
->assertSuccessful()
|
||||
->assertNotified('.env updated!');
|
||||
|
||||
SSH::assertFileUploaded('/home/vito/'.$this->site->domain.'/.env', 'APP_ENV="production"');
|
||||
}
|
||||
@ -200,7 +215,7 @@ public function test_git_hook_deployment(): void
|
||||
], 200),
|
||||
]);
|
||||
|
||||
$hook = GitHook::factory()->create([
|
||||
GitHook::factory()->create([
|
||||
'site_id' => $this->site->id,
|
||||
'source_control_id' => $this->site->source_control_id,
|
||||
'secret' => 'secret',
|
||||
@ -228,7 +243,7 @@ public function test_git_hook_deployment_invalid_secret(): void
|
||||
SSH::fake();
|
||||
Http::fake();
|
||||
|
||||
$hook = GitHook::factory()->create([
|
||||
GitHook::factory()->create([
|
||||
'site_id' => $this->site->id,
|
||||
'source_control_id' => $this->site->source_control_id,
|
||||
'secret' => 'secret',
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Facades\SSH;
|
||||
use App\Web\Pages\Servers\Console\Index;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
@ -14,7 +15,7 @@ public function test_see_console(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$this->get(route('servers.console', $this->server))
|
||||
$this->get(Index::getUrl(['server' => $this->server]))
|
||||
->assertSuccessful()
|
||||
->assertSeeText('Headless Console');
|
||||
}
|
||||
|
@ -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();
|
||||
|
||||
|
@ -17,7 +17,10 @@ public function test_create_rules(): void
|
||||
]));
|
||||
|
||||
$this->assertSame([
|
||||
'webhook_url' => 'required|url',
|
||||
'webhook_url' => [
|
||||
'required',
|
||||
'url',
|
||||
],
|
||||
], $provider->createRules([]));
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,10 @@ public function test_create_rules(): void
|
||||
]));
|
||||
|
||||
$this->assertSame([
|
||||
'email' => 'required|email',
|
||||
'email' => [
|
||||
'required',
|
||||
'email',
|
||||
],
|
||||
], $provider->createRules([]));
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,10 @@ public function test_create_rules(): void
|
||||
]));
|
||||
|
||||
$this->assertSame([
|
||||
'webhook_url' => 'required|url',
|
||||
'webhook_url' => [
|
||||
'required',
|
||||
'url',
|
||||
],
|
||||
], $provider->createRules([]));
|
||||
}
|
||||
|
||||
|
@ -17,8 +17,12 @@ public function test_create_rules(): void
|
||||
]));
|
||||
|
||||
$this->assertSame([
|
||||
'bot_token' => 'required|string',
|
||||
'chat_id' => 'required',
|
||||
'bot_token' => [
|
||||
'required',
|
||||
],
|
||||
'chat_id' => [
|
||||
'required',
|
||||
],
|
||||
], $provider->createRules([]));
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user