mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-02 14:36:17 +00:00
init
This commit is contained in:
69
tests/Feature/Http/ApplicationTest.php
Normal file
69
tests/Feature/Http/ApplicationTest.php
Normal file
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Http;
|
||||
|
||||
use App\Http\Livewire\Application\ChangeBranch;
|
||||
use App\Http\Livewire\Application\Deploy;
|
||||
use App\Http\Livewire\Application\DeploymentScript;
|
||||
use App\Http\Livewire\Application\LaravelApp;
|
||||
use App\Jobs\Site\UpdateBranch;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Bus;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ApplicationTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_visit_application()
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$this->get(
|
||||
route('servers.sites.application', [
|
||||
'server' => $this->server,
|
||||
'site' => $this->site
|
||||
])
|
||||
)
|
||||
->assertOk()
|
||||
->assertSeeLivewire(LaravelApp::class);
|
||||
}
|
||||
|
||||
public function test_update_deployment_script()
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(Deploy::class, ['site' => $this->site])
|
||||
->assertDontSeeText('Deploy');
|
||||
|
||||
Livewire::test(DeploymentScript::class, ['site' => $this->site])
|
||||
->set('script', 'some script')
|
||||
->call('save')
|
||||
->assertSuccessful();
|
||||
|
||||
$this->assertDatabaseHas('deployment_scripts', [
|
||||
'site_id' => $this->site->id,
|
||||
'content' => 'some script'
|
||||
]);
|
||||
|
||||
$this->site->refresh();
|
||||
|
||||
Livewire::test(Deploy::class, ['site' => $this->site])
|
||||
->assertSeeText('Deploy');
|
||||
}
|
||||
|
||||
public function test_change_branch()
|
||||
{
|
||||
Bus::fake();
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ChangeBranch::class, ['site' => $this->site])
|
||||
->set('branch', 'master')
|
||||
->call('change')
|
||||
->assertSuccessful();
|
||||
|
||||
Bus::assertDispatched(UpdateBranch::class);
|
||||
}
|
||||
}
|
40
tests/Feature/Http/Auth/AuthenticationTest.php
Normal file
40
tests/Feature/Http/Auth/AuthenticationTest.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Http\Auth;
|
||||
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class AuthenticationTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_login_screen_can_be_rendered(): void
|
||||
{
|
||||
$response = $this->get('/login');
|
||||
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
public function test_users_can_authenticate_using_the_login_screen(): void
|
||||
{
|
||||
$response = $this->post('/login', [
|
||||
'email' => $this->user->email,
|
||||
'password' => 'password',
|
||||
]);
|
||||
|
||||
$this->assertAuthenticated();
|
||||
$response->assertRedirect(RouteServiceProvider::HOME);
|
||||
}
|
||||
|
||||
public function test_users_can_not_authenticate_with_invalid_password(): void
|
||||
{
|
||||
$this->post('/login', [
|
||||
'email' => $this->user->email,
|
||||
'password' => 'wrong-password',
|
||||
]);
|
||||
|
||||
$this->assertGuest();
|
||||
}
|
||||
}
|
47
tests/Feature/Http/Auth/PasswordConfirmationTest.php
Normal file
47
tests/Feature/Http/Auth/PasswordConfirmationTest.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Http\Auth;
|
||||
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use JsonException;
|
||||
use Tests\TestCase;
|
||||
|
||||
class PasswordConfirmationTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_confirm_password_screen_can_be_rendered(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$response = $this->get('/confirm-password');
|
||||
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws JsonException
|
||||
*/
|
||||
public function test_password_can_be_confirmed(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$response = $this->post('/confirm-password', [
|
||||
'password' => 'password',
|
||||
]);
|
||||
|
||||
$response->assertRedirect();
|
||||
$response->assertSessionHasNoErrors();
|
||||
}
|
||||
|
||||
public function test_password_is_not_confirmed_with_invalid_password(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$response = $this->post('/confirm-password', [
|
||||
'password' => 'wrong-password',
|
||||
]);
|
||||
|
||||
$response->assertSessionHasErrors();
|
||||
}
|
||||
}
|
64
tests/Feature/Http/Auth/PasswordResetTest.php
Normal file
64
tests/Feature/Http/Auth/PasswordResetTest.php
Normal file
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Http\Auth;
|
||||
|
||||
use Illuminate\Auth\Notifications\ResetPassword;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use Tests\TestCase;
|
||||
|
||||
class PasswordResetTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_reset_password_link_screen_can_be_rendered(): void
|
||||
{
|
||||
$response = $this->get('/forgot-password');
|
||||
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
public function test_reset_password_link_can_be_requested(): void
|
||||
{
|
||||
Notification::fake();
|
||||
|
||||
$this->post('/forgot-password', ['email' => $this->user->email]);
|
||||
|
||||
Notification::assertSentTo($this->user, ResetPassword::class);
|
||||
}
|
||||
|
||||
public function test_reset_password_screen_can_be_rendered(): void
|
||||
{
|
||||
Notification::fake();
|
||||
|
||||
$this->post('/forgot-password', ['email' => $this->user->email]);
|
||||
|
||||
Notification::assertSentTo($this->user, ResetPassword::class, function ($notification) {
|
||||
$response = $this->get('/reset-password/'.$notification->token);
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
public function test_password_can_be_reset_with_valid_token(): void
|
||||
{
|
||||
Notification::fake();
|
||||
|
||||
$this->post('/forgot-password', ['email' => $this->user->email]);
|
||||
|
||||
Notification::assertSentTo($this->user, ResetPassword::class, function ($notification) {
|
||||
$response = $this->post('/reset-password', [
|
||||
'token' => $notification->token,
|
||||
'email' => $this->user->email,
|
||||
'password' => 'password',
|
||||
'password_confirmation' => 'password',
|
||||
]);
|
||||
|
||||
$response->assertSessionHasNoErrors();
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
40
tests/Feature/Http/Auth/PasswordUpdateTest.php
Normal file
40
tests/Feature/Http/Auth/PasswordUpdateTest.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Http\Auth;
|
||||
|
||||
use App\Http\Livewire\Profile\UpdatePassword;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
class PasswordUpdateTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_password_can_be_updated(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(UpdatePassword::class)
|
||||
->set('current_password', 'password')
|
||||
->set('password', 'new-password')
|
||||
->set('password_confirmation', 'new-password')
|
||||
->call('update')
|
||||
->assertSuccessful();
|
||||
|
||||
$this->assertTrue(Hash::check('new-password', $this->user->refresh()->password));
|
||||
}
|
||||
|
||||
public function test_correct_password_must_be_provided_to_update_password(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(UpdatePassword::class)
|
||||
->set('current_password', 'wrong-password')
|
||||
->set('password', 'new-password')
|
||||
->set('password_confirmation', 'new-password')
|
||||
->call('update')
|
||||
->assertHasErrors();
|
||||
}
|
||||
}
|
64
tests/Feature/Http/CronjobTest.php
Normal file
64
tests/Feature/Http/CronjobTest.php
Normal file
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Http;
|
||||
|
||||
use App\Enums\CronjobStatus;
|
||||
use App\Http\Livewire\Cronjobs\CreateCronjob;
|
||||
use App\Http\Livewire\Cronjobs\CronjobsList;
|
||||
use App\Models\CronJob;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
class CronjobTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_see_cronjobs_list()
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
/** @var CronJob $cronjob */
|
||||
$cronjob = CronJob::factory()->create([
|
||||
'server_id' => $this->server->id,
|
||||
]);
|
||||
|
||||
Livewire::test(CronjobsList::class, ['server' => $this->server])
|
||||
->assertSeeText($cronjob->frequency_label);
|
||||
}
|
||||
|
||||
public function test_delete_cronjob()
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
/** @var CronJob $cronjob */
|
||||
$cronjob = CronJob::factory()->create([
|
||||
'server_id' => $this->server->id,
|
||||
]);
|
||||
|
||||
Livewire::test(CronjobsList::class, ['server' => $this->server])
|
||||
->set('deleteId', $cronjob->id)
|
||||
->call('delete')
|
||||
->assertDispatchedBrowserEvent('confirmed', true);
|
||||
}
|
||||
|
||||
public function test_create_cronjob()
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(CreateCronjob::class, ['server' => $this->server])
|
||||
->set('command', 'ls -la')
|
||||
->set('user', 'vito')
|
||||
->set('frequency', '* * * * *')
|
||||
->call('create')
|
||||
->assertDispatchedBrowserEvent('created', true);
|
||||
|
||||
$this->assertDatabaseHas('cron_jobs', [
|
||||
'server_id' => $this->server->id,
|
||||
'command' => 'ls -la',
|
||||
'user' => 'vito',
|
||||
'frequency' => '* * * * *',
|
||||
'status' => CronjobStatus::CREATING
|
||||
]);
|
||||
}
|
||||
}
|
76
tests/Feature/Http/DatabaseTest.php
Normal file
76
tests/Feature/Http/DatabaseTest.php
Normal file
@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Http;
|
||||
|
||||
use App\Enums\DatabaseStatus;
|
||||
use App\Facades\SSH;
|
||||
use App\Http\Livewire\Databases\DatabaseList;
|
||||
use App\Jobs\Database\CreateOnServer;
|
||||
use App\Jobs\Database\DeleteFromServer;
|
||||
use App\Models\Database;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Bus;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
class DatabaseTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_create_database(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Bus::fake();
|
||||
|
||||
SSH::fake()->outputShouldBe('test');
|
||||
|
||||
Livewire::test(DatabaseList::class, ['server' => $this->server])
|
||||
->set('name', 'database')
|
||||
->call('create')
|
||||
->assertSuccessful();
|
||||
|
||||
Bus::assertDispatched(CreateOnServer::class);
|
||||
|
||||
$this->assertDatabaseHas('databases', [
|
||||
'name' => 'database',
|
||||
'status' => DatabaseStatus::CREATING,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_see_databases_list(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$database = Database::factory()->create([
|
||||
'server_id' => $this->server,
|
||||
]);
|
||||
|
||||
Livewire::test(DatabaseList::class, ['server' => $this->server])
|
||||
->assertSee([
|
||||
$database->name,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_delete_database(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Bus::fake();
|
||||
|
||||
$database = Database::factory()->create([
|
||||
'server_id' => $this->server,
|
||||
]);
|
||||
|
||||
Livewire::test(DatabaseList::class, ['server' => $this->server])
|
||||
->set('deleteId', $database->id)
|
||||
->call('delete');
|
||||
|
||||
$this->assertDatabaseHas('databases', [
|
||||
'id' => $database->id,
|
||||
'status' => DatabaseStatus::DELETING,
|
||||
]);
|
||||
|
||||
Bus::assertDispatched(DeleteFromServer::class);
|
||||
}
|
||||
}
|
74
tests/Feature/Http/DatabaseUserTest.php
Normal file
74
tests/Feature/Http/DatabaseUserTest.php
Normal file
@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Http;
|
||||
|
||||
use App\Enums\DatabaseUserStatus;
|
||||
use App\Http\Livewire\Databases\DatabaseUserList;
|
||||
use App\Jobs\DatabaseUser\CreateOnServer;
|
||||
use App\Jobs\DatabaseUser\DeleteFromServer;
|
||||
use App\Models\DatabaseUser;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Bus;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
class DatabaseUserTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_create_database_user(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Bus::fake();
|
||||
|
||||
Livewire::test(DatabaseUserList::class, ['server' => $this->server])
|
||||
->set('username', 'user')
|
||||
->set('password', 'password')
|
||||
->call('create')
|
||||
->assertSuccessful();
|
||||
|
||||
Bus::assertDispatched(CreateOnServer::class);
|
||||
|
||||
$this->assertDatabaseHas('database_users', [
|
||||
'username' => 'user',
|
||||
'status' => DatabaseUserStatus::CREATING,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_see_database_users_list(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$databaseUser = DatabaseUser::factory()->create([
|
||||
'server_id' => $this->server,
|
||||
]);
|
||||
|
||||
Livewire::test(DatabaseUserList::class, ['server' => $this->server])
|
||||
->assertSee([
|
||||
$databaseUser->username,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_delete_database_user(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Bus::fake();
|
||||
|
||||
$databaseUser = DatabaseUser::factory()->create([
|
||||
'server_id' => $this->server,
|
||||
]);
|
||||
|
||||
Livewire::test(DatabaseUserList::class, ['server' => $this->server])
|
||||
->set('deleteId', $databaseUser->id)
|
||||
->call('delete');
|
||||
|
||||
$this->assertDatabaseHas('database_users', [
|
||||
'id' => $databaseUser->id,
|
||||
'status' => DatabaseUserStatus::DELETING,
|
||||
]);
|
||||
|
||||
Bus::assertDispatched(DeleteFromServer::class);
|
||||
}
|
||||
}
|
79
tests/Feature/Http/FirewallTest.php
Normal file
79
tests/Feature/Http/FirewallTest.php
Normal file
@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Http;
|
||||
|
||||
use App\Enums\FirewallRuleStatus;
|
||||
use App\Http\Livewire\Firewall\CreateFirewallRule;
|
||||
use App\Http\Livewire\Firewall\FirewallRulesList;
|
||||
use App\Jobs\Firewall\AddToServer;
|
||||
use App\Jobs\Firewall\RemoveFromServer;
|
||||
use App\Models\FirewallRule;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Bus;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
class FirewallTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_create_firewall_rule(): void
|
||||
{
|
||||
Bus::fake();
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(CreateFirewallRule::class, ['server' => $this->server])
|
||||
->set('type', 'allow')
|
||||
->set('protocol', 'tcp')
|
||||
->set('port', '1234')
|
||||
->set('source', '0.0.0.0')
|
||||
->set('mask', '0')
|
||||
->call('create')
|
||||
->assertSuccessful();
|
||||
|
||||
Bus::assertDispatched(AddToServer::class);
|
||||
|
||||
$this->assertDatabaseHas('firewall_rules', [
|
||||
'port' => '1234'
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_see_firewall_rules(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$rule = FirewallRule::factory()->create([
|
||||
'server_id' => $this->server->id
|
||||
]);
|
||||
|
||||
Livewire::test(FirewallRulesList::class, ['server' => $this->server])
|
||||
->assertSee([
|
||||
$rule->source,
|
||||
$rule->port,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_delete_firewall_rule(): void
|
||||
{
|
||||
Bus::fake();
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$rule = FirewallRule::factory()->create([
|
||||
'server_id' => $this->server->id
|
||||
]);
|
||||
|
||||
Livewire::test(FirewallRulesList::class, ['server' => $this->server])
|
||||
->set('deleteId', $rule->id)
|
||||
->call('delete')
|
||||
->assertSuccessful();
|
||||
|
||||
Bus::assertDispatched(RemoveFromServer::class);
|
||||
|
||||
$this->assertDatabaseHas('firewall_rules', [
|
||||
'id' => $rule->id,
|
||||
'status' => FirewallRuleStatus::DELETING
|
||||
]);
|
||||
}
|
||||
}
|
30
tests/Feature/Http/LogsTest.php
Normal file
30
tests/Feature/Http/LogsTest.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Http;
|
||||
|
||||
use App\Http\Livewire\ServerLogs\LogsList;
|
||||
use App\Models\ServerLog;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
class LogsTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_see_logs()
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
/** @var ServerLog $log */
|
||||
$log = ServerLog::factory()->create([
|
||||
'server_id' => $this->server->id,
|
||||
]);
|
||||
|
||||
$this->get(route('servers.logs', $this->server))
|
||||
->assertOk();
|
||||
|
||||
Livewire::test(LogsList::class, ['server' => $this->server])
|
||||
->assertSeeText($log->type);
|
||||
}
|
||||
}
|
85
tests/Feature/Http/NotificationChannelsTest.php
Normal file
85
tests/Feature/Http/NotificationChannelsTest.php
Normal file
@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Http;
|
||||
|
||||
use App\Enums\NotificationChannel;
|
||||
use App\Http\Livewire\NotificationChannels\AddChannel;
|
||||
use App\Http\Livewire\NotificationChannels\ChannelsList;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
class NotificationChannelsTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
use WithFaker;
|
||||
|
||||
public function test_add_email_channel(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(AddChannel::class)
|
||||
->set('provider', NotificationChannel::EMAIL)
|
||||
->set('email', 'email@example.com')
|
||||
->call('add')
|
||||
->assertSuccessful();
|
||||
}
|
||||
|
||||
public function test_add_slack_channel(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Http::fake();
|
||||
|
||||
Livewire::test(AddChannel::class)
|
||||
->set('provider', NotificationChannel::SLACK)
|
||||
->set('label', 'Slack')
|
||||
->set('webhook_url', $this->faker->url)
|
||||
->call('add')
|
||||
->assertSuccessful();
|
||||
}
|
||||
|
||||
public function test_add_discord_channel(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Http::fake();
|
||||
|
||||
Livewire::test(AddChannel::class)
|
||||
->set('provider', NotificationChannel::DISCORD)
|
||||
->set('label', 'Slack')
|
||||
->set('webhook_url', $this->faker->url)
|
||||
->call('add')
|
||||
->assertSuccessful();
|
||||
}
|
||||
|
||||
public function test_see_channels_list(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$channel = \App\Models\NotificationChannel::factory()->create();
|
||||
|
||||
Livewire::test(ChannelsList::class)
|
||||
->assertSee([
|
||||
$channel->provider,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_delete_channel(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$channel = \App\Models\NotificationChannel::factory()->create();
|
||||
|
||||
Livewire::test(ChannelsList::class)
|
||||
->set('deleteId', $channel->id)
|
||||
->call('delete')
|
||||
->assertSuccessful();
|
||||
|
||||
$this->assertDatabaseMissing('notification_channels', [
|
||||
'id' => $channel->id,
|
||||
]);
|
||||
}
|
||||
}
|
71
tests/Feature/Http/PHP.php
Normal file
71
tests/Feature/Http/PHP.php
Normal file
@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Http;
|
||||
|
||||
use App\Enums\ServiceStatus;
|
||||
use App\Http\Livewire\Php\DefaultCli;
|
||||
use App\Http\Livewire\Php\InstalledVersions;
|
||||
use App\Jobs\Installation\InstallPHP;
|
||||
use App\Jobs\Installation\UninstallPHP;
|
||||
use App\Jobs\PHP\SetDefaultCli;
|
||||
use App\Models\Service;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Bus;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
class PHP extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_install_new_php(): void
|
||||
{
|
||||
Bus::fake();
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(InstalledVersions::class, ['server' => $this->server])
|
||||
->call('install', '8.1')
|
||||
->assertSuccessful();
|
||||
|
||||
Bus::assertDispatched(InstallPHP::class);
|
||||
}
|
||||
|
||||
public function test_uninstall_new_php(): void
|
||||
{
|
||||
Bus::fake();
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(InstalledVersions::class, ['server' => $this->server])
|
||||
->set('uninstallId', $this->server->php('8.2')?->id)
|
||||
->call('uninstall')
|
||||
->assertSuccessful();
|
||||
|
||||
Bus::assertDispatched(UninstallPHP::class);
|
||||
}
|
||||
|
||||
public function test_change_default_php_cli(): void
|
||||
{
|
||||
Bus::fake();
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Service::factory()->create([
|
||||
'server_id' => $this->server->id,
|
||||
'type' => 'php',
|
||||
'type_data' => [
|
||||
'extensions' => [],
|
||||
],
|
||||
'name' => 'php',
|
||||
'version' => '8.1',
|
||||
'status' => ServiceStatus::READY
|
||||
]);
|
||||
|
||||
Livewire::test(DefaultCli::class, ['server' => $this->server])
|
||||
->call('change', '8.1')
|
||||
->assertSuccessful();
|
||||
|
||||
Bus::assertDispatched(SetDefaultCli::class);
|
||||
}
|
||||
}
|
40
tests/Feature/Http/ProfileTest.php
Normal file
40
tests/Feature/Http/ProfileTest.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Http;
|
||||
|
||||
use App\Http\Livewire\Profile\UpdatePassword;
|
||||
use App\Http\Livewire\Profile\UpdateProfileInformation;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ProfileTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_profile_page_is_displayed(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$this
|
||||
->get(route('profile'))
|
||||
->assertSeeLivewire(UpdateProfileInformation::class)
|
||||
->assertSeeLivewire(UpdatePassword::class);
|
||||
}
|
||||
|
||||
public function test_profile_information_can_be_updated(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(UpdateProfileInformation::class)
|
||||
->set('name', 'Test')
|
||||
->set('email', 'test@example.com')
|
||||
->call('submit')
|
||||
->assertSuccessful();
|
||||
|
||||
$this->user->refresh();
|
||||
|
||||
$this->assertSame('Test', $this->user->name);
|
||||
$this->assertSame('test@example.com', $this->user->email);
|
||||
}
|
||||
}
|
69
tests/Feature/Http/QueuesTest.php
Normal file
69
tests/Feature/Http/QueuesTest.php
Normal file
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Http;
|
||||
|
||||
use App\Enums\QueueStatus;
|
||||
use App\Http\Livewire\Queues\CreateQueue;
|
||||
use App\Http\Livewire\Queues\QueuesList;
|
||||
use App\Models\Queue;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
class QueuesTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_see_queues()
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$queue = Queue::factory()->create([
|
||||
'server_id' => $this->server->id,
|
||||
'site_id' => $this->site->id,
|
||||
]);
|
||||
|
||||
Livewire::test(QueuesList::class, ['site' => $this->site])
|
||||
->assertSeeText($queue->command);
|
||||
}
|
||||
|
||||
public function test_delete_queue()
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$queue = Queue::factory()->create([
|
||||
'server_id' => $this->server->id,
|
||||
'site_id' => $this->site->id,
|
||||
]);
|
||||
|
||||
Livewire::test(QueuesList::class, ['site' => $this->site])
|
||||
->set('deleteId', $queue->id)
|
||||
->call('delete')
|
||||
->assertDispatchedBrowserEvent('confirmed', true);
|
||||
}
|
||||
|
||||
public function test_create_queue()
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(CreateQueue::class, ['site' => $this->site])
|
||||
->set('command', 'php artisan queue:work')
|
||||
->set('user', 'vito')
|
||||
->set('auto_start', 1)
|
||||
->set('auto_restart', 1)
|
||||
->set('numprocs', 1)
|
||||
->call('create')
|
||||
->assertDispatchedBrowserEvent('created', true);
|
||||
|
||||
$this->assertDatabaseHas('queues', [
|
||||
'server_id' => $this->server->id,
|
||||
'site_id' => $this->site->id,
|
||||
'command' => 'php artisan queue:work',
|
||||
'user' => 'vito',
|
||||
'auto_start' => 1,
|
||||
'auto_restart' => 1,
|
||||
'numprocs' => 1,
|
||||
'status' => QueueStatus::CREATING
|
||||
]);
|
||||
}
|
||||
}
|
111
tests/Feature/Http/ServerKeysTest.php
Normal file
111
tests/Feature/Http/ServerKeysTest.php
Normal file
@ -0,0 +1,111 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Http;
|
||||
|
||||
use App\Enums\SshKeyStatus;
|
||||
use App\Http\Livewire\ServerSshKeys\AddExistingKey;
|
||||
use App\Http\Livewire\ServerSshKeys\AddNewKey;
|
||||
use App\Http\Livewire\ServerSshKeys\ServerKeysList;
|
||||
use App\Jobs\SshKey\DeleteSshKeyFromServer;
|
||||
use App\Jobs\SshKey\DeploySshKeyToServer;
|
||||
use App\Models\SshKey;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Bus;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ServerKeysTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_see_server_keys()
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$sshKey = SshKey::factory()->create([
|
||||
'user_id' => $this->user->id,
|
||||
'name' => 'My first key',
|
||||
'public_key' => 'public-key-content',
|
||||
]);
|
||||
|
||||
$this->server->sshKeys()->attach($sshKey);
|
||||
|
||||
Livewire::test(ServerKeysList::class, ['server' => $this->server])
|
||||
->assertSeeText('My first key');
|
||||
}
|
||||
|
||||
public function test_delete_ssh_key()
|
||||
{
|
||||
Bus::fake();
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$sshKey = SshKey::factory()->create([
|
||||
'user_id' => $this->user->id,
|
||||
'name' => 'My first key',
|
||||
'public_key' => 'public-key-content',
|
||||
]);
|
||||
|
||||
$this->server->sshKeys()->attach($sshKey);
|
||||
|
||||
Livewire::test(ServerKeysList::class, ['server' => $this->server])
|
||||
->set('deleteId', $sshKey->id)
|
||||
->call('delete')
|
||||
->assertDispatchedBrowserEvent('confirmed');
|
||||
|
||||
$this->assertDatabaseHas('server_ssh_keys', [
|
||||
'server_id' => $this->server->id,
|
||||
'ssh_key_id' => $sshKey->id,
|
||||
'status' => SshKeyStatus::DELETING
|
||||
]);
|
||||
|
||||
Bus::assertDispatched(DeleteSshKeyFromServer::class);
|
||||
}
|
||||
|
||||
public function test_add_new_ssh_key()
|
||||
{
|
||||
Bus::fake();
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(AddNewKey::class, ['server' => $this->server])
|
||||
->set('name', 'My first key')
|
||||
->set('public_key', 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC3CCnyBbpCgOJ0AWUSfBZ+mYAsYzcQDegPkBx1kyE0bXT1yX4+6uYx1Jh6NxWgLyaU0BaP4nsClrK1u5FojQHd8J7ycc0N3H8B+v2NPzj1Q6bFnl40saastONVm+d4edbCg9BowGAafLcf9ALsognqqOWQbK/QOpAhg25IAe47eiY3IjDGMHlsvaZkMtkDhT4t1mK8ZLjxw5vjyVYgINJefR981bIxMFrXy+0xBCsYOZxMIoAJsgCkrAGlI4kQHKv0SQVccSyTE1eziIZa5b3QUlXj8ogxMfK/EOD7Aoqinw652k4S5CwFs/LLmjWcFqCKDM6CSggWpB78DZ729O6zFvQS9V99/9SsSV7Qc5ML7B0DKzJ/tbHkaAE8xdZnQnZFVUegUMtUmjvngMaGlYsxkAZrUKsFRoh7xfXVkDyRBaBSslRNe8LFsXw9f7Q+3jdZ5vhGhmp+TBXTlgxApwR023411+ABE9y0doCx8illya3m2olEiiMZkRclgqsWFSk=')
|
||||
->call('add')
|
||||
->assertSuccessful()
|
||||
->assertDispatchedBrowserEvent('added');
|
||||
|
||||
$this->assertDatabaseHas('server_ssh_keys', [
|
||||
'server_id' => $this->server->id,
|
||||
'status' => SshKeyStatus::ADDING
|
||||
]);
|
||||
|
||||
Bus::assertDispatched(DeploySshKeyToServer::class);
|
||||
}
|
||||
|
||||
public function test_add_existing_key()
|
||||
{
|
||||
Bus::fake();
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$sshKey = SshKey::factory()->create([
|
||||
'user_id' => $this->user->id,
|
||||
'name' => 'My first key',
|
||||
'public_key' => 'public-key-content',
|
||||
]);
|
||||
|
||||
Livewire::test(AddExistingKey::class, ['server' => $this->server])
|
||||
->set('key_id', $sshKey->id)
|
||||
->call('add')
|
||||
->assertSuccessful()
|
||||
->assertDispatchedBrowserEvent('added');
|
||||
|
||||
$this->assertDatabaseHas('server_ssh_keys', [
|
||||
'server_id' => $this->server->id,
|
||||
'status' => SshKeyStatus::ADDING
|
||||
]);
|
||||
|
||||
Bus::assertDispatched(DeploySshKeyToServer::class);
|
||||
}
|
||||
}
|
67
tests/Feature/Http/ServerProvidersTest.php
Normal file
67
tests/Feature/Http/ServerProvidersTest.php
Normal file
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Http;
|
||||
|
||||
use App\Enums\ServerProvider;
|
||||
use App\Http\Livewire\ServerProviders\ConnectProvider;
|
||||
use App\Http\Livewire\ServerProviders\ProvidersList;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ServerProvidersTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_connect_hetzner(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Http::fake();
|
||||
|
||||
Livewire::test(ConnectProvider::class)
|
||||
->set('provider', ServerProvider::HETZNER)
|
||||
->set('name', 'profile')
|
||||
->set('token', 'token')
|
||||
->call('connect')
|
||||
->assertSuccessful();
|
||||
|
||||
$this->assertDatabaseHas('server_providers', [
|
||||
'provider' => ServerProvider::HETZNER,
|
||||
'profile' => 'profile',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_see_providers_list(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$provider = \App\Models\ServerProvider::factory()->create([
|
||||
'user_id' => $this->user->id,
|
||||
]);
|
||||
|
||||
Livewire::test(ProvidersList::class)
|
||||
->assertSee([
|
||||
$provider->profile,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_delete_provider(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$provider = \App\Models\ServerProvider::factory()->create([
|
||||
'user_id' => $this->user->id,
|
||||
]);
|
||||
|
||||
Livewire::test(ProvidersList::class)
|
||||
->set('deleteId', $provider->id)
|
||||
->call('delete')
|
||||
->assertSuccessful();
|
||||
|
||||
$this->assertDatabaseMissing('server_providers', [
|
||||
'id' => $provider->id,
|
||||
]);
|
||||
}
|
||||
}
|
47
tests/Feature/Http/ServerTest.php
Normal file
47
tests/Feature/Http/ServerTest.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Http;
|
||||
|
||||
use App\Enums\Database;
|
||||
use App\Enums\OperatingSystem;
|
||||
use App\Enums\ServerProvider;
|
||||
use App\Enums\ServerStatus;
|
||||
use App\Enums\Webserver;
|
||||
use App\Http\Livewire\Servers\CreateServer;
|
||||
use App\Jobs\Installation\Initialize;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Bus;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ServerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_create_custom_server(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Bus::fake();
|
||||
|
||||
Livewire::test(CreateServer::class)
|
||||
->set('provider', ServerProvider::CUSTOM)
|
||||
->set('name', 'test')
|
||||
->set('ip', '1.1.1.1')
|
||||
->set('port', '22')
|
||||
->set('os', OperatingSystem::UBUNTU22)
|
||||
->set('webserver', Webserver::NGINX)
|
||||
->set('database', Database::MYSQL80)
|
||||
->set('php', '8.2')
|
||||
->call('submit')
|
||||
->assertSuccessful();
|
||||
|
||||
$this->assertDatabaseHas('servers', [
|
||||
'name' => 'test',
|
||||
'ip' => '1.1.1.1',
|
||||
'status' => ServerStatus::INSTALLING,
|
||||
]);
|
||||
|
||||
Bus::assertDispatched(Initialize::class);
|
||||
}
|
||||
}
|
94
tests/Feature/Http/ServicesTest.php
Normal file
94
tests/Feature/Http/ServicesTest.php
Normal file
@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Http;
|
||||
|
||||
use App\Enums\ServiceStatus;
|
||||
use App\Http\Livewire\Services\ServicesList;
|
||||
use App\Jobs\Service\Manage;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Bus;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ServicesTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_see_services_list(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ServicesList::class, ['server' => $this->server])
|
||||
->assertSee([
|
||||
'nginx',
|
||||
'php',
|
||||
'supervisor',
|
||||
'redis',
|
||||
'ufw',
|
||||
'php'
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider data
|
||||
*/
|
||||
public function test_restart_service(string $name): void
|
||||
{
|
||||
$service = $this->server->services()->where('name', $name)->first();
|
||||
|
||||
Bus::fake();
|
||||
|
||||
Livewire::test(ServicesList::class, ['server' => $this->server])
|
||||
->call('restart', $service->id)
|
||||
->assertSuccessful();
|
||||
|
||||
Bus::assertDispatched(Manage::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider data
|
||||
*/
|
||||
public function test_stop_service(string $name): void
|
||||
{
|
||||
$service = $this->server->services()->where('name', $name)->first();
|
||||
|
||||
Bus::fake();
|
||||
|
||||
Livewire::test(ServicesList::class, ['server' => $this->server])
|
||||
->call('stop', $service->id)
|
||||
->assertSuccessful();
|
||||
|
||||
Bus::assertDispatched(Manage::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider data
|
||||
*/
|
||||
public function test_start_service(string $name): void
|
||||
{
|
||||
$service = $this->server->services()->where('name', $name)->first();
|
||||
|
||||
$service->status = ServiceStatus::STOPPED;
|
||||
$service->save();
|
||||
|
||||
Bus::fake();
|
||||
|
||||
Livewire::test(ServicesList::class, ['server' => $this->server])
|
||||
->call('start', $service->id)
|
||||
->assertSuccessful();
|
||||
|
||||
Bus::assertDispatched(Manage::class);
|
||||
}
|
||||
|
||||
public static function data(): array
|
||||
{
|
||||
return [
|
||||
['nginx'],
|
||||
['php'],
|
||||
['supervisor'],
|
||||
['redis'],
|
||||
['ufw'],
|
||||
['php'],
|
||||
];
|
||||
}
|
||||
}
|
111
tests/Feature/Http/SitesTest.php
Normal file
111
tests/Feature/Http/SitesTest.php
Normal file
@ -0,0 +1,111 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Http;
|
||||
|
||||
use App\Enums\SiteStatus;
|
||||
use App\Enums\SiteType;
|
||||
use App\Enums\SourceControl;
|
||||
use App\Http\Livewire\Sites\ChangePhpVersion;
|
||||
use App\Http\Livewire\Sites\CreateSite;
|
||||
use App\Http\Livewire\Sites\DeleteSite;
|
||||
use App\Http\Livewire\Sites\SitesList;
|
||||
use App\Jobs\Site\CreateVHost;
|
||||
use App\Models\Site;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Bus;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SitesTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_create_site(): void
|
||||
{
|
||||
Bus::fake();
|
||||
|
||||
Http::fake();
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
\App\Models\SourceControl::factory()->create([
|
||||
'provider' => SourceControl::GITHUB,
|
||||
]);
|
||||
|
||||
Livewire::test(CreateSite::class, ['server' => $this->server])
|
||||
->set('type', SiteType::LARAVEL)
|
||||
->set('domain', 'example.com')
|
||||
->set('alias', 'www.example.com')
|
||||
->set('php_version', '8.2')
|
||||
->set('web_directory', 'public')
|
||||
->set('source_control', SourceControl::GITHUB)
|
||||
->set('repository', 'test/test')
|
||||
->set('branch', 'main')
|
||||
->set('composer', true)
|
||||
->call('create')
|
||||
->assertSuccessful()
|
||||
->assertHasNoErrors();
|
||||
|
||||
Bus::assertDispatched(CreateVHost::class);
|
||||
|
||||
$this->assertDatabaseHas('sites', [
|
||||
'domain' => 'example.com',
|
||||
'status' => SiteStatus::INSTALLING,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_see_sites_list(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$site = Site::factory()->create([
|
||||
'server_id' => $this->server->id,
|
||||
]);
|
||||
|
||||
Livewire::test(SitesList::class, ['server' => $this->server])
|
||||
->assertSee([
|
||||
$site->domain,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_delete_site(): void
|
||||
{
|
||||
Bus::fake();
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$site = Site::factory()->create([
|
||||
'server_id' => $this->server->id,
|
||||
]);
|
||||
|
||||
Livewire::test(DeleteSite::class, ['server' => $this->server])
|
||||
->set('site', $site)
|
||||
->call('delete')
|
||||
->assertSuccessful();
|
||||
|
||||
Bus::assertDispatched(\App\Jobs\Site\DeleteSite::class);
|
||||
|
||||
$site->refresh();
|
||||
|
||||
$this->assertEquals(SiteStatus::DELETING, $site->status);
|
||||
}
|
||||
|
||||
public function test_change_php_version(): void
|
||||
{
|
||||
Bus::fake();
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$site = Site::factory()->create([
|
||||
'server_id' => $this->server->id,
|
||||
]);
|
||||
|
||||
Livewire::test(ChangePhpVersion::class, ['site' => $site])
|
||||
->set('version', '8.1')
|
||||
->call('change')
|
||||
->assertSuccessful();
|
||||
|
||||
Bus::assertDispatched(\App\Jobs\Site\ChangePHPVersion::class);
|
||||
}
|
||||
}
|
66
tests/Feature/Http/SourceControlsTest.php
Normal file
66
tests/Feature/Http/SourceControlsTest.php
Normal file
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Http;
|
||||
|
||||
use App\Http\Livewire\SourceControls\Bitbucket;
|
||||
use App\Http\Livewire\SourceControls\Github;
|
||||
use App\Http\Livewire\SourceControls\Gitlab;
|
||||
use App\Models\SourceControl;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SourceControlsTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* @dataProvider data
|
||||
*/
|
||||
public function test_connect_provider(string $provider, string $component): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Http::fake();
|
||||
|
||||
Livewire::test($component)
|
||||
->set('token', 'token')
|
||||
->call('connect')
|
||||
->assertSuccessful();
|
||||
|
||||
$this->assertDatabaseHas('source_controls', [
|
||||
'provider' => $provider,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider data
|
||||
*/
|
||||
public function test_delete_provider(string $provider, string $component): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
SourceControl::factory()->create([
|
||||
'provider' => $provider,
|
||||
]);
|
||||
|
||||
Livewire::test($component)
|
||||
->set('token', '')
|
||||
->call('connect')
|
||||
->assertSuccessful();
|
||||
|
||||
$this->assertDatabaseMissing('source_controls', [
|
||||
'provider' => $provider,
|
||||
]);
|
||||
}
|
||||
|
||||
public static function data(): array
|
||||
{
|
||||
return [
|
||||
['github', Github::class],
|
||||
['gitlab', Gitlab::class],
|
||||
['bitbucket', Bitbucket::class],
|
||||
];
|
||||
}
|
||||
}
|
61
tests/Feature/Http/SshKeysTest.php
Normal file
61
tests/Feature/Http/SshKeysTest.php
Normal file
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Http;
|
||||
|
||||
use App\Http\Livewire\SshKeys\AddKey;
|
||||
use App\Http\Livewire\SshKeys\KeysList;
|
||||
use App\Models\SshKey;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SshKeysTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_create_ssh_key(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(AddKey::class)
|
||||
->set('name', 'test')
|
||||
->set(
|
||||
'public_key',
|
||||
'ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAklOUpkDHrfHY17SbrmTIpNLTGK9Tjom/BWDSUGPl+nafzlHDTYW7hdI4yZ5ew18JH4JW9jbhUFrviQzM7xlELEVf4h9lFX5QVkbPppSwg0cda3Pbv7kOdJ/MTyBlWXFCR+HAo3FXRitBqxiX1nKhXpHAZsMciLq8V6RjsNAQwdsdMFvSlVK/7XAt3FaoJoAsncM1Q9x5+3V0Ww68/eIFmb1zuUFljQJKprrX88XypNDvjYNby6vw/Pb0rwert/EnmZ+AW4OZPnTPI89ZPmVMLuayrD2cE86Z/il8b+gw3r3+1nKatmIkjn2so1d01QraTlMqVSsbxNrRFi9wrf+M7Q== test@test.local'
|
||||
)
|
||||
->call('add')
|
||||
->assertSuccessful();
|
||||
}
|
||||
|
||||
public function test_get_public_keys_list(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$key = SshKey::factory()->create([
|
||||
'user_id' => $this->user->id,
|
||||
]);
|
||||
|
||||
Livewire::test(KeysList::class)
|
||||
->assertSee([
|
||||
$key->name,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_delete_key(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$key = SshKey::factory()->create([
|
||||
'user_id' => $this->user->id,
|
||||
]);
|
||||
|
||||
Livewire::test(KeysList::class)
|
||||
->set('deleteId', $key->id)
|
||||
->call('delete')
|
||||
->assertSuccessful();
|
||||
|
||||
$this->assertDatabaseMissing('ssh_keys', [
|
||||
'id' => $key->id,
|
||||
]);
|
||||
}
|
||||
}
|
83
tests/Feature/Http/SslTest.php
Normal file
83
tests/Feature/Http/SslTest.php
Normal file
@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Http;
|
||||
|
||||
use App\Enums\SslStatus;
|
||||
use App\Enums\SslType;
|
||||
use App\Http\Livewire\Ssl\CreateSsl;
|
||||
use App\Http\Livewire\Ssl\SslsList;
|
||||
use App\Jobs\Ssl\Deploy;
|
||||
use App\Jobs\Ssl\Remove;
|
||||
use App\Models\Ssl;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Bus;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SslTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_see_ssls_list()
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$ssl = Ssl::factory()->create([
|
||||
'site_id' => $this->site->id,
|
||||
]);
|
||||
|
||||
Livewire::test(SslsList::class, ['site' => $this->site])
|
||||
->assertSeeText($ssl->type);
|
||||
}
|
||||
|
||||
public function test_see_ssls_list_with_no_ssls()
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(SslsList::class, ['site' => $this->site])
|
||||
->assertSeeText(__("You don't have any SSL certificates yet!"));
|
||||
}
|
||||
|
||||
public function test_create_ssl()
|
||||
{
|
||||
Bus::fake();
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(CreateSsl::class, ['site' => $this->site])
|
||||
->set('type', SslType::LETSENCRYPT)
|
||||
->call('create')
|
||||
->assertDispatchedBrowserEvent('created');
|
||||
|
||||
$this->assertDatabaseHas('ssls', [
|
||||
'site_id' => $this->site->id,
|
||||
'type' => SslType::LETSENCRYPT,
|
||||
'status' => SslStatus::CREATING,
|
||||
]);
|
||||
|
||||
Bus::assertDispatched(Deploy::class);
|
||||
}
|
||||
|
||||
public function test_delete_ssl()
|
||||
{
|
||||
Bus::fake();
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$ssl = Ssl::factory()->create([
|
||||
'site_id' => $this->site->id,
|
||||
]);
|
||||
|
||||
Livewire::test(SslsList::class, ['site' => $this->site])
|
||||
->set('deleteId', $ssl->id)
|
||||
->call('delete')
|
||||
->assertDispatchedBrowserEvent('confirmed');
|
||||
|
||||
$this->assertDatabaseHas('ssls', [
|
||||
'id' => $ssl->id,
|
||||
'status' => SslStatus::DELETING,
|
||||
]);
|
||||
|
||||
Bus::assertDispatched(Remove::class);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user