Migrate to HTMX (#114)

Dropped Livewire
Added HTMX
Added Blade code lint
Drop Mysql and Redis
Migrate to SQLite
This commit is contained in:
Saeed Vaziry
2024-03-06 17:02:59 +01:00
committed by GitHub
parent 5b2c419e91
commit b2083fc6b2
486 changed files with 8609 additions and 8707 deletions

View File

@ -2,17 +2,11 @@
namespace Tests\Feature;
use App\Http\Livewire\Application\AutoDeployment;
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 App\Models\GitHook;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Bus;
use Illuminate\Support\Facades\Http;
use Livewire\Livewire;
use Tests\TestCase;
class ApplicationTest extends TestCase
@ -30,30 +24,27 @@ public function test_visit_application()
])
)
->assertOk()
->assertSeeLivewire(LaravelApp::class);
->assertSee($this->site->domain);
}
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->post(
route('servers.sites.application.deployment-script', [
'server' => $this->server,
'site' => $this->site,
]),
[
'script' => 'some script',
]
)->assertSessionDoesntHaveErrors();
$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()
@ -62,10 +53,12 @@ public function test_change_branch()
$this->actingAs($this->user);
Livewire::test(ChangeBranch::class, ['site' => $this->site])
->set('branch', 'master')
->call('change')
->assertSuccessful();
$this->post(route('servers.sites.application.branch', [
'server' => $this->server,
'site' => $this->site,
]), [
'branch' => 'master',
])->assertSessionDoesntHaveErrors();
Bus::assertDispatched(UpdateBranch::class);
}
@ -80,9 +73,10 @@ public function test_enable_auto_deployment()
$this->actingAs($this->user);
Livewire::test(AutoDeployment::class, ['site' => $this->site])
->call('enable')
->assertSuccessful();
$this->post(route('servers.sites.application.auto-deployment', [
'server' => $this->server,
'site' => $this->site,
]))->assertSessionDoesntHaveErrors();
$this->site->refresh();
@ -102,9 +96,10 @@ public function test_disable_auto_deployment()
'source_control_id' => $this->site->source_control_id,
]);
Livewire::test(AutoDeployment::class, ['site' => $this->site])
->call('disable')
->assertSuccessful();
$this->delete(route('servers.sites.application.auto-deployment', [
'server' => $this->server,
'site' => $this->site,
]))->assertSessionDoesntHaveErrors();
$this->site->refresh();

View File

@ -1,40 +0,0 @@
<?php
namespace Tests\Feature\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();
}
}

View File

@ -3,11 +3,9 @@
namespace Tests\Feature;
use App\Enums\CronjobStatus;
use App\Http\Livewire\Cronjobs\CreateCronjob;
use App\Http\Livewire\Cronjobs\CronjobsList;
use App\Facades\SSH;
use App\Models\CronJob;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Livewire;
use Tests\TestCase;
class CronjobTest extends TestCase
@ -23,12 +21,14 @@ public function test_see_cronjobs_list()
'server_id' => $this->server->id,
]);
Livewire::test(CronjobsList::class, ['server' => $this->server])
$this->get(route('servers.cronjobs', $this->server))
->assertSeeText($cronjob->frequency_label);
}
public function test_delete_cronjob()
{
SSH::fake();
$this->actingAs($this->user);
/** @var CronJob $cronjob */
@ -36,29 +36,34 @@ public function test_delete_cronjob()
'server_id' => $this->server->id,
]);
Livewire::test(CronjobsList::class, ['server' => $this->server])
->set('deleteId', $cronjob->id)
->call('delete')
->assertDispatched('confirmed');
$this->delete(route('servers.cronjobs.destroy', [
'server' => $this->server,
'cronJob' => $cronjob,
]))->assertSessionHasNoErrors();
$this->assertDatabaseMissing('cron_jobs', [
'id' => $cronjob->id,
]);
}
public function test_create_cronjob()
{
SSH::fake();
$this->actingAs($this->user);
Livewire::test(CreateCronjob::class, ['server' => $this->server])
->set('command', 'ls -la')
->set('user', 'vito')
->set('frequency', '* * * * *')
->call('create')
->assertDispatched('created');
$this->post(route('servers.cronjobs.store', $this->server), [
'command' => 'ls -la',
'user' => 'vito',
'frequency' => '* * * * *',
])->assertSessionHasNoErrors();
$this->assertDatabaseHas('cron_jobs', [
'server_id' => $this->server->id,
'command' => 'ls -la',
'user' => 'vito',
'frequency' => '* * * * *',
'status' => CronjobStatus::CREATING,
'status' => CronjobStatus::READY,
]);
}
}

View File

@ -4,14 +4,12 @@
use App\Enums\BackupStatus;
use App\Facades\SSH;
use App\Http\Livewire\Databases\DatabaseBackups;
use App\Jobs\Backup\RunBackup;
use App\Models\Backup;
use App\Models\Database;
use App\Models\StorageProvider;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Bus;
use Livewire\Livewire;
use Tests\TestCase;
class DatabaseBackupTest extends TestCase
@ -35,13 +33,12 @@ public function test_create_backup(): void
'provider' => \App\Enums\StorageProvider::DROPBOX,
]);
Livewire::test(DatabaseBackups::class, ['server' => $this->server])
->set('database', $database->id)
->set('storage', $storage->id)
->set('interval', '0 * * * *')
->set('keep', '10')
->call('create')
->assertSuccessful();
$this->post(route('servers.databases.backups.store', $this->server), [
'backup_database' => $database->id,
'backup_storage' => $storage->id,
'backup_interval' => '0 * * * *',
'backup_keep' => '10',
])->assertSessionHasNoErrors();
Bus::assertDispatched(RunBackup::class);
@ -69,10 +66,8 @@ public function test_see_backups_list(): void
'storage_id' => $storage->id,
]);
Livewire::test(DatabaseBackups::class, ['server' => $this->server])
->assertSee([
$backup->database->name,
]);
$this->get(route('servers.databases.backups', [$this->server, $backup]))
->assertSee($backup->database->name);
}
public function test_delete_database(): void
@ -94,9 +89,8 @@ public function test_delete_database(): void
'storage_id' => $storage->id,
]);
Livewire::test(DatabaseBackups::class, ['server' => $this->server])
->set('deleteId', $backup->id)
->call('delete');
$this->delete(route('servers.databases.backups.destroy', [$this->server, $backup]))
->assertSessionHasNoErrors();
$this->assertDatabaseMissing('backups', [
'id' => $backup->id,

View File

@ -4,13 +4,8 @@
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
@ -21,20 +16,15 @@ 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->post(route('servers.databases.store', $this->server), [
'name' => 'database',
])->assertSessionHasNoErrors();
$this->assertDatabaseHas('databases', [
'name' => 'database',
'status' => DatabaseStatus::CREATING,
'status' => DatabaseStatus::READY,
]);
}
@ -46,31 +36,25 @@ public function test_see_databases_list(): void
'server_id' => $this->server,
]);
Livewire::test(DatabaseList::class, ['server' => $this->server])
->assertSee([
$database->name,
]);
$this->get(route('servers.databases', $this->server))
->assertSee($database->name);
}
public function test_delete_database(): void
{
$this->actingAs($this->user);
Bus::fake();
SSH::fake()->outputShouldBe('test');
$database = Database::factory()->create([
'server_id' => $this->server,
]);
Livewire::test(DatabaseList::class, ['server' => $this->server])
->set('deleteId', $database->id)
->call('delete');
$this->delete(route('servers.databases.destroy', [$this->server, $database]))
->assertSessionHasNoErrors();
$this->assertDatabaseHas('databases', [
$this->assertDatabaseMissing('databases', [
'id' => $database->id,
'status' => DatabaseStatus::DELETING,
]);
Bus::assertDispatched(DeleteFromServer::class);
}
}

View File

@ -3,13 +3,9 @@
namespace Tests\Feature;
use App\Enums\DatabaseUserStatus;
use App\Http\Livewire\Databases\DatabaseUserList;
use App\Jobs\DatabaseUser\CreateOnServer;
use App\Jobs\DatabaseUser\DeleteFromServer;
use App\Facades\SSH;
use App\Models\DatabaseUser;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Bus;
use Livewire\Livewire;
use Tests\TestCase;
class DatabaseUserTest extends TestCase
@ -20,19 +16,16 @@ public function test_create_database_user(): void
{
$this->actingAs($this->user);
Bus::fake();
SSH::fake();
Livewire::test(DatabaseUserList::class, ['server' => $this->server])
->set('username', 'user')
->set('password', 'password')
->call('create')
->assertSuccessful();
Bus::assertDispatched(CreateOnServer::class);
$this->post(route('servers.databases.users.store', $this->server), [
'username' => 'user',
'password' => 'password',
])->assertSessionHasNoErrors();
$this->assertDatabaseHas('database_users', [
'username' => 'user',
'status' => DatabaseUserStatus::CREATING,
'status' => DatabaseUserStatus::READY,
]);
}
@ -44,31 +37,25 @@ public function test_see_database_users_list(): void
'server_id' => $this->server,
]);
Livewire::test(DatabaseUserList::class, ['server' => $this->server])
->assertSee([
$databaseUser->username,
]);
$this->get(route('servers.databases', $this->server))
->assertSee($databaseUser->username);
}
public function test_delete_database_user(): void
{
$this->actingAs($this->user);
Bus::fake();
SSH::fake();
$databaseUser = DatabaseUser::factory()->create([
'server_id' => $this->server,
]);
Livewire::test(DatabaseUserList::class, ['server' => $this->server])
->set('deleteId', $databaseUser->id)
->call('delete');
$this->delete(route('servers.databases.users.destroy', [$this->server, $databaseUser]))
->assertSessionHasNoErrors();
$this->assertDatabaseHas('database_users', [
$this->assertDatabaseMissing('database_users', [
'id' => $databaseUser->id,
'status' => DatabaseUserStatus::DELETING,
]);
Bus::assertDispatched(DeleteFromServer::class);
}
}

View File

@ -3,14 +3,9 @@
namespace Tests\Feature;
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\Facades\SSH;
use App\Models\FirewallRule;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Bus;
use Livewire\Livewire;
use Tests\TestCase;
class FirewallTest extends TestCase
@ -19,23 +14,21 @@ class FirewallTest extends TestCase
public function test_create_firewall_rule(): void
{
Bus::fake();
SSH::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->post(route('servers.firewall.store', $this->server), [
'type' => 'allow',
'protocol' => 'tcp',
'port' => '1234',
'source' => '0.0.0.0',
'mask' => '0',
])->assertSessionHasNoErrors();
$this->assertDatabaseHas('firewall_rules', [
'port' => '1234',
'status' => FirewallRuleStatus::READY,
]);
}
@ -47,16 +40,14 @@ public function test_see_firewall_rules(): void
'server_id' => $this->server->id,
]);
Livewire::test(FirewallRulesList::class, ['server' => $this->server])
->assertSee([
$rule->source,
$rule->port,
]);
$this->get(route('servers.firewall', $this->server))
->assertSee($rule->source)
->assertSee($rule->port);
}
public function test_delete_firewall_rule(): void
{
Bus::fake();
SSH::fake();
$this->actingAs($this->user);
@ -64,16 +55,13 @@ public function test_delete_firewall_rule(): void
'server_id' => $this->server->id,
]);
Livewire::test(FirewallRulesList::class, ['server' => $this->server])
->set('deleteId', $rule->id)
->call('delete')
->assertSuccessful();
$this->delete(route('servers.firewall.destroy', [
'server' => $this->server,
'firewallRule' => $rule,
]))->assertSessionHasNoErrors();
Bus::assertDispatched(RemoveFromServer::class);
$this->assertDatabaseHas('firewall_rules', [
$this->assertDatabaseMissing('firewall_rules', [
'id' => $rule->id,
'status' => FirewallRuleStatus::DELETING,
]);
}
}

View File

@ -2,10 +2,8 @@
namespace Tests\Feature;
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
@ -22,9 +20,6 @@ public function test_see_logs()
]);
$this->get(route('servers.logs', $this->server))
->assertOk();
Livewire::test(LogsList::class, ['server' => $this->server])
->assertSeeText($log->type);
}
}

View File

@ -3,12 +3,10 @@
namespace Tests\Feature;
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 JsonException;
use Tests\TestCase;
class NotificationChannelsTest extends TestCase
@ -16,16 +14,18 @@ class NotificationChannelsTest extends TestCase
use RefreshDatabase;
use WithFaker;
/**
* @throws JsonException
*/
public function test_add_email_channel(): void
{
$this->actingAs($this->user);
Livewire::test(AddChannel::class)
->set('provider', NotificationChannel::EMAIL)
->set('email', 'email@example.com')
->set('label', 'Email')
->call('add')
->assertSuccessful();
$this->post(route('notification-channels.add'), [
'provider' => NotificationChannel::EMAIL,
'email' => 'email@example.com',
'label' => 'Email',
])->assertSessionHasNoErrors();
/** @var \App\Models\NotificationChannel $channel */
$channel = \App\Models\NotificationChannel::query()
@ -36,18 +36,20 @@ public function test_add_email_channel(): void
$this->assertTrue($channel->connected);
}
/**
* @throws JsonException
*/
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', 'https://hooks.slack.com/services/123/token')
->call('add')
->assertSuccessful();
$this->post(route('notification-channels.add'), [
'provider' => NotificationChannel::SLACK,
'webhook_url' => 'https://hooks.slack.com/services/123/token',
'label' => 'Slack',
])->assertSessionHasNoErrors();
/** @var \App\Models\NotificationChannel $channel */
$channel = \App\Models\NotificationChannel::query()
@ -58,18 +60,20 @@ public function test_add_slack_channel(): void
$this->assertTrue($channel->connected);
}
/**
* @throws JsonException
*/
public function test_add_discord_channel(): void
{
$this->actingAs($this->user);
Http::fake();
Livewire::test(AddChannel::class)
->set('provider', NotificationChannel::DISCORD)
->set('label', 'Discord')
->set('webhook_url', 'https://discord.com/api/webhooks/123/token')
->call('add')
->assertSuccessful();
$this->post(route('notification-channels.add'), [
'provider' => NotificationChannel::DISCORD,
'webhook_url' => 'https://discord.com/api/webhooks/123/token',
'label' => 'Discord',
])->assertSessionHasNoErrors();
/** @var \App\Models\NotificationChannel $channel */
$channel = \App\Models\NotificationChannel::query()
@ -83,19 +87,21 @@ public function test_add_discord_channel(): void
/*
* @TODO fix json comparison
*/
/**
* @throws JsonException
*/
public function test_add_telegram_channel(): void
{
$this->actingAs($this->user);
Http::fake();
Livewire::test(AddChannel::class)
->set('provider', NotificationChannel::TELEGRAM)
->set('label', 'Telegram')
->set('bot_token', 'token')
->set('chat_id', '123')
->call('add')
->assertSuccessful();
$this->post(route('notification-channels.add'), [
'provider' => NotificationChannel::TELEGRAM,
'bot_token' => 'token',
'chat_id' => '123',
'label' => 'Telegram',
])->assertSessionHasNoErrors();
/** @var \App\Models\NotificationChannel $channel */
$channel = \App\Models\NotificationChannel::query()
@ -113,22 +119,21 @@ public function test_see_channels_list(): void
$channel = \App\Models\NotificationChannel::factory()->create();
Livewire::test(ChannelsList::class)
->assertSee([
$channel->provider,
]);
$this->get(route('notification-channels'))
->assertSee($channel->provider);
}
/**
* @throws JsonException
*/
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->delete(route('notification-channels.delete', $channel->id))
->assertSessionHasNoErrors();
$this->assertDatabaseMissing('notification_channels', [
'id' => $channel->id,

View File

@ -1,110 +0,0 @@
<?php
namespace Tests\Feature;
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\InstallPHPExtension;
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);
}
public function test_install_extension(): void
{
Bus::fake();
$this->actingAs($this->user);
Livewire::test(InstalledVersions::class, ['server' => $this->server])
->set('extensionId', $this->server->php('8.2')?->id)
->set('extension', 'gmp')
->call('installExtension')
->assertSuccessful();
Bus::assertDispatched(InstallPHPExtension::class);
}
public function test_extension_already_installed(): void
{
Bus::fake();
$this->actingAs($this->user);
$this->server->php('8.2')->update([
'type_data' => [
'extensions' => [
'gmp',
],
],
]);
Livewire::test(InstalledVersions::class, ['server' => $this->server])
->set('extensionId', $this->server->php('8.2')?->id)
->set('extension', 'gmp')
->call('installExtension')
->assertSuccessful();
Bus::assertNotDispatched(InstallPHPExtension::class);
}
}

132
tests/Feature/PHPTest.php Normal file
View File

@ -0,0 +1,132 @@
<?php
namespace Tests\Feature;
use App\Enums\ServiceStatus;
use App\Jobs\Installation\InstallPHP;
use App\Jobs\Installation\UninstallPHP;
use App\Jobs\PHP\InstallPHPExtension;
use App\Models\Service;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Bus;
use Tests\TestCase;
class PHPTest extends TestCase
{
use RefreshDatabase;
public function test_install_new_php(): void
{
Bus::fake();
$this->actingAs($this->user);
$this->post(route('servers.php.install', [
'server' => $this->server,
'version' => '8.1',
]))->assertSessionHasNoErrors();
Bus::assertDispatched(InstallPHP::class);
}
public function test_uninstall_php(): void
{
Bus::fake();
$this->actingAs($this->user);
$php = new Service([
'server_id' => $this->server->id,
'type' => 'php',
'type_data' => [
'extensions' => [],
'settings' => config('core.php_settings'),
],
'name' => 'php',
'version' => '8.1',
'status' => ServiceStatus::READY,
'is_default' => true,
]);
$php->save();
$this->delete(route('servers.php.uninstall', [
'server' => $this->server,
'version' => '8.1',
]))->assertSessionHasNoErrors();
Bus::assertDispatched(UninstallPHP::class);
}
public function test_cannot_uninstall_php(): void
{
$this->actingAs($this->user);
$this->delete(route('servers.php.uninstall', [
'server' => $this->server,
'version' => '8.2',
]))->assertSessionHasErrors();
}
public function test_change_default_php_cli(): void
{
$this->actingAs($this->user);
$php = Service::factory()->create([
'server_id' => $this->server->id,
'type' => 'php',
'type_data' => [
'extensions' => [],
],
'name' => 'php',
'version' => '8.1',
'status' => ServiceStatus::READY,
]);
$this->post(route('servers.php.default-cli', [
'server' => $this->server,
'version' => '8.1',
]))->assertSessionHasNoErrors();
$php->refresh();
$this->assertTrue($php->is_default);
}
public function test_install_extension(): void
{
Bus::fake();
$this->actingAs($this->user);
$this->post(route('servers.php.install-extension', [
'server' => $this->server,
'version' => '8.2',
'extension' => 'gmp',
]))->assertSessionHasNoErrors();
Bus::assertDispatched(InstallPHPExtension::class);
}
public function test_extension_already_installed(): void
{
Bus::fake();
$this->actingAs($this->user);
$this->server->php('8.2')->update([
'type_data' => [
'extensions' => [
'gmp',
],
],
]);
$this->post(route('servers.php.install-extension', [
'server' => $this->server,
'version' => '8.2',
'extension' => 'gmp',
]))->assertSessionHasErrors();
Bus::assertNotDispatched(InstallPHPExtension::class);
}
}

View File

@ -2,10 +2,8 @@
namespace Tests\Feature;
use App\Http\Livewire\Profile\UpdatePassword;
use App\Http\Livewire\Profile\UpdateProfileInformation;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Livewire;
use Illuminate\Support\Facades\Hash;
use Tests\TestCase;
class ProfileTest extends TestCase
@ -18,20 +16,20 @@ public function test_profile_page_is_displayed(): void
$this
->get(route('profile'))
->assertSeeLivewire(UpdateProfileInformation::class)
->assertSeeLivewire(UpdatePassword::class);
->assertSee('Profile Information')
->assertSee('Update Password')
->assertSee('Two Factor Authentication');
}
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')
->set('timezone', 'Europe/Berlin')
->call('submit')
->assertSuccessful();
$this->post(route('profile.info'), [
'name' => 'Test',
'email' => 'test@example.com',
'timezone' => 'Europe/Berlin',
]);
$this->user->refresh();
@ -39,4 +37,28 @@ public function test_profile_information_can_be_updated(): void
$this->assertSame('test@example.com', $this->user->email);
$this->assertSame('Europe/Berlin', $this->user->timezone);
}
public function test_password_can_be_updated(): void
{
$this->actingAs($this->user);
$this->post(route('profile.password'), [
'current_password' => 'password',
'password' => 'new-password',
'password_confirmation' => 'new-password',
]);
$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);
$this->post(route('profile.password'), [
'current_password' => 'wrong-password',
'password' => 'new-password',
'password_confirmation' => 'new-password',
])->assertSessionHasErrors('current_password');
}
}

View File

@ -2,26 +2,25 @@
namespace Tests\Feature;
use App\Http\Livewire\Projects\CreateProject;
use App\Http\Livewire\Projects\EditProject;
use App\Http\Livewire\Projects\ProjectsList;
use App\Models\Project;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Livewire;
use JsonException;
use Tests\TestCase;
class ProjectsTest extends TestCase
{
use RefreshDatabase;
/**
* @throws JsonException
*/
public function test_create_project(): void
{
$this->actingAs($this->user);
Livewire::test(CreateProject::class)
->set('inputs.name', 'test')
->call('create')
->assertSuccessful();
$this->post(route('projects.create'), [
'name' => 'test',
])->assertSessionHasNoErrors();
$this->assertDatabaseHas('projects', [
'name' => 'test',
@ -36,12 +35,13 @@ public function test_see_projects_list(): void
'user_id' => $this->user->id,
]);
Livewire::test(ProjectsList::class)
->assertSee([
$project->name,
]);
$this->get(route('projects'))
->assertSee($project->name);
}
/**
* @throws JsonException
*/
public function test_delete_project(): void
{
$this->actingAs($this->user);
@ -50,16 +50,17 @@ public function test_delete_project(): void
'user_id' => $this->user->id,
]);
Livewire::test(ProjectsList::class)
->set('deleteId', $project->id)
->call('delete')
->assertSuccessful();
$this->delete(route('projects.delete', $project))
->assertSessionHasNoErrors();
$this->assertDatabaseMissing('projects', [
'id' => $project->id,
]);
}
/**
* @throws JsonException
*/
public function test_edit_project(): void
{
$this->actingAs($this->user);
@ -68,16 +69,13 @@ public function test_edit_project(): void
'user_id' => $this->user->id,
]);
Livewire::test(EditProject::class, [
'project' => $project,
])
->set('inputs.name', 'test')
->call('save')
->assertSuccessful();
$this->post(route('projects.update', $project), [
'name' => 'new-name',
])->assertSessionHasNoErrors();
$this->assertDatabaseHas('projects', [
'id' => $project->id,
'name' => 'test',
'name' => 'new-name',
]);
}
}

View File

@ -3,11 +3,8 @@
namespace Tests\Feature;
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
@ -23,8 +20,14 @@ public function test_see_queues()
'site_id' => $this->site->id,
]);
Livewire::test(QueuesList::class, ['site' => $this->site])
->assertSeeText($queue->command);
$this->get(
route('servers.sites.queues', [
'server' => $this->server,
'site' => $this->site,
])
)
->assertOk()
->assertSee($queue->command);
}
public function test_delete_queue()
@ -36,24 +39,37 @@ public function test_delete_queue()
'site_id' => $this->site->id,
]);
Livewire::test(QueuesList::class, ['site' => $this->site])
->set('deleteId', $queue->id)
->call('delete')
->assertDispatched('confirmed');
$this->delete(
route('servers.sites.queues.destroy', [
'server' => $this->server,
'site' => $this->site,
'queue' => $queue,
])
)->assertRedirect();
$this->assertDatabaseHas('queues', [
'id' => $queue->id,
'status' => QueueStatus::DELETING,
]);
}
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')
->assertDispatched('created');
$this->post(
route('servers.sites.queues.store', [
'server' => $this->server,
'site' => $this->site,
]),
[
'command' => 'php artisan queue:work',
'user' => 'vito',
'auto_start' => 1,
'auto_restart' => 1,
'numprocs' => 1,
]
)->assertSessionDoesntHaveErrors();
$this->assertDatabaseHas('queues', [
'server_id' => $this->server->id,

View File

@ -3,15 +3,11 @@
namespace Tests\Feature;
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
@ -32,7 +28,7 @@ public function test_see_server_keys()
'status' => SshKeyStatus::ADDED,
]);
Livewire::test(ServerKeysList::class, ['server' => $this->server])
$this->get(route('servers.ssh-keys', $this->server))
->assertSeeText('My first key');
}
@ -52,10 +48,7 @@ public function test_delete_ssh_key()
'status' => SshKeyStatus::ADDED,
]);
Livewire::test(ServerKeysList::class, ['server' => $this->server])
->set('deleteId', $sshKey->id)
->call('delete')
->assertDispatched('confirmed');
$this->delete(route('servers.ssh-keys.destroy', [$this->server, $sshKey]));
$this->assertDatabaseHas('server_ssh_keys', [
'server_id' => $this->server->id,
@ -72,12 +65,10 @@ public function test_add_new_ssh_key()
$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()
->assertDispatched('added');
$this->post(route('servers.ssh-keys.store', $this->server), [
'name' => 'My first key',
'public_key' => 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC3CCnyBbpCgOJ0AWUSfBZ+mYAsYzcQDegPkBx1kyE0bXT1yX4+6uYx1Jh6NxWgLyaU0BaP4nsClrK1u5FojQHd8J7ycc0N3H8B+v2NPzj1Q6bFnl40saastONVm+d4edbCg9BowGAafLcf9ALsognqqOWQbK/QOpAhg25IAe47eiY3IjDGMHlsvaZkMtkDhT4t1mK8ZLjxw5vjyVYgINJefR981bIxMFrXy+0xBCsYOZxMIoAJsgCkrAGlI4kQHKv0SQVccSyTE1eziIZa5b3QUlXj8ogxMfK/EOD7Aoqinw652k4S5CwFs/LLmjWcFqCKDM6CSggWpB78DZ729O6zFvQS9V99/9SsSV7Qc5ML7B0DKzJ/tbHkaAE8xdZnQnZFVUegUMtUmjvngMaGlYsxkAZrUKsFRoh7xfXVkDyRBaBSslRNe8LFsXw9f7Q+3jdZ5vhGhmp+TBXTlgxApwR023411+ABE9y0doCx8illya3m2olEiiMZkRclgqsWFSk=',
]);
$this->assertDatabaseHas('server_ssh_keys', [
'server_id' => $this->server->id,
@ -99,11 +90,9 @@ public function test_add_existing_key()
'public_key' => 'public-key-content',
]);
Livewire::test(AddExistingKey::class, ['server' => $this->server])
->set('key_id', $sshKey->id)
->call('add')
->assertSuccessful()
->assertDispatched('added');
$this->post(route('servers.ssh-keys.deploy', $this->server), [
'key_id' => $sshKey->id,
]);
$this->assertDatabaseHas('server_ssh_keys', [
'server_id' => $this->server->id,

View File

@ -3,29 +3,29 @@
namespace Tests\Feature;
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 JsonException;
use Tests\TestCase;
class ServerProvidersTest extends TestCase
{
use RefreshDatabase;
/**
* @throws JsonException
*/
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->post(route('server-providers.connect'), [
'provider' => ServerProvider::HETZNER,
'name' => 'profile',
'token' => 'token',
])->assertSessionHasNoErrors();
$this->assertDatabaseHas('server_providers', [
'provider' => ServerProvider::HETZNER,
@ -41,12 +41,13 @@ public function test_see_providers_list(): void
'user_id' => $this->user->id,
]);
Livewire::test(ProvidersList::class)
->assertSee([
$provider->profile,
]);
$this->get(route('server-providers'))
->assertSee($provider->profile);
}
/**
* @throws JsonException
*/
public function test_delete_provider(): void
{
$this->actingAs($this->user);
@ -55,10 +56,8 @@ public function test_delete_provider(): void
'user_id' => $this->user->id,
]);
Livewire::test(ProvidersList::class)
->set('deleteId', $provider->id)
->call('delete')
->assertSuccessful();
$this->delete(route('server-providers.delete', $provider->id))
->assertSessionHasNoErrors();
$this->assertDatabaseMissing('server_providers', [
'id' => $provider->id,

View File

@ -6,35 +6,41 @@
use App\Enums\OperatingSystem;
use App\Enums\ServerProvider;
use App\Enums\ServerStatus;
use App\Enums\ServerType;
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 JsonException;
use Tests\TestCase;
/**
* @TODO add more tests
*/
class ServerTest extends TestCase
{
use RefreshDatabase;
/**
* @throws JsonException
*/
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->post(route('servers.create'), [
'type' => ServerType::REGULAR,
'provider' => ServerProvider::CUSTOM,
'name' => 'test',
'ip' => '1.1.1.1',
'port' => '22',
'os' => OperatingSystem::UBUNTU22,
'webserver' => Webserver::NGINX,
'database' => Database::MYSQL80,
'php' => '8.2',
])->assertSessionHasNoErrors();
$this->assertDatabaseHas('servers', [
'name' => 'test',

View File

@ -3,15 +3,12 @@
namespace Tests\Feature;
use App\Enums\ServiceStatus;
use App\Http\Livewire\Services\InstallPHPMyAdmin;
use App\Http\Livewire\Services\ServicesList;
use App\Jobs\Installation\InstallPHPMyAdmin as InstallationInstallPHPMyAdmin;
use App\Jobs\Installation\UninstallPHPMyAdmin;
use App\Jobs\Service\Manage;
use App\Models\Service;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Bus;
use Livewire\Livewire;
use Tests\TestCase;
class ServicesTest extends TestCase
@ -22,15 +19,12 @@ 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',
]);
$this->get(route('servers.services', $this->server))
->assertSee('nginx')
->assertSee('php')
->assertSee('supervisor')
->assertSee('redis')
->assertSee('ufw');
}
/**
@ -38,13 +32,16 @@ public function test_see_services_list(): void
*/
public function test_restart_service(string $name): void
{
$service = $this->server->services()->where('name', $name)->first();
$this->actingAs($this->user);
$service = $this->server->services()->where('name', $name)->firstOrFail();
Bus::fake();
Livewire::test(ServicesList::class, ['server' => $this->server])
->call('restart', $service->id)
->assertSuccessful();
$this->get(route('servers.services.restart', [
'server' => $this->server,
'service' => $service,
]))->assertSessionHasNoErrors();
Bus::assertDispatched(Manage::class);
}
@ -54,13 +51,16 @@ public function test_restart_service(string $name): void
*/
public function test_stop_service(string $name): void
{
$this->actingAs($this->user);
$service = $this->server->services()->where('name', $name)->first();
Bus::fake();
Livewire::test(ServicesList::class, ['server' => $this->server])
->call('stop', $service->id)
->assertSuccessful();
$this->get(route('servers.services.stop', [
'server' => $this->server,
'service' => $service,
]))->assertSessionHasNoErrors();
Bus::assertDispatched(Manage::class);
}
@ -70,6 +70,8 @@ public function test_stop_service(string $name): void
*/
public function test_start_service(string $name): void
{
$this->actingAs($this->user);
$service = $this->server->services()->where('name', $name)->first();
$service->status = ServiceStatus::STOPPED;
@ -77,28 +79,27 @@ public function test_start_service(string $name): void
Bus::fake();
Livewire::test(ServicesList::class, ['server' => $this->server])
->call('start', $service->id)
->assertSuccessful();
$this->get(route('servers.services.start', [
'server' => $this->server,
'service' => $service,
]))->assertSessionHasNoErrors();
Bus::assertDispatched(Manage::class);
}
public function test_install_phpmyadmin(): void
{
Bus::fake();
$this->markTestSkipped('PHPMyAdmin is depricated');
Livewire::test(InstallPHPMyAdmin::class, ['server' => $this->server])
->set('allowed_ip', '0.0.0.0')
->set('port', 5433)
->call('install')
->assertSuccessful();
Bus::fake();
Bus::assertDispatched(InstallationInstallPHPMyAdmin::class);
}
public function test_uninstall_phpmyadmin(): void
{
$this->markTestSkipped('PHPMyAdmin is depricated');
$service = Service::factory()->create([
'server_id' => $this->server->id,
'type' => 'phpmyadmin',
@ -116,10 +117,6 @@ public function test_uninstall_phpmyadmin(): void
Bus::fake();
Livewire::test(ServicesList::class, ['server' => $this->server])
->call('uninstall', $service->id)
->assertSuccessful();
Bus::assertDispatched(UninstallPHPMyAdmin::class);
}

View File

@ -6,18 +6,11 @@
use App\Enums\SiteType;
use App\Enums\SourceControl;
use App\Facades\SSH;
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\Http\Livewire\Sites\UpdateSourceControlProvider;
use App\Http\Livewire\Sites\UpdateVHost;
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
@ -40,12 +33,11 @@ public function test_create_site(array $inputs): void
'provider' => SourceControl::GITHUB,
]);
Livewire::test(CreateSite::class, ['server' => $this->server])
->fill($inputs)
->set('inputs.source_control', $sourceControl->id)
->call('create')
->assertSuccessful()
->assertHasNoErrors();
$inputs['source_control'] = $sourceControl->id;
$this->post(route('servers.sites.create', [
'server' => $this->server,
]), $inputs)->assertSessionDoesntHaveErrors();
Bus::assertDispatched(CreateVHost::class);
@ -63,10 +55,11 @@ public function test_see_sites_list(): void
'server_id' => $this->server->id,
]);
Livewire::test(SitesList::class, ['server' => $this->server])
->assertSee([
$site->domain,
]);
$this->get(route('servers.sites', [
'server' => $this->server,
]))
->assertOk()
->assertSee($site->domain);
}
public function test_delete_site(): void
@ -79,10 +72,10 @@ public function test_delete_site(): void
'server_id' => $this->server->id,
]);
Livewire::test(DeleteSite::class, ['server' => $this->server])
->set('site', $site)
->call('delete')
->assertSuccessful();
$this->delete(route('servers.sites.destroy', [
'server' => $this->server,
'site' => $site,
]))->assertRedirect();
Bus::assertDispatched(\App\Jobs\Site\DeleteSite::class);
@ -93,20 +86,22 @@ public function test_delete_site(): void
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();
$this->post(route('servers.sites.settings.php', [
'server' => $this->server,
'site' => $site,
]), [
'version' => '8.2',
])->assertSessionDoesntHaveErrors();
Bus::assertDispatched(\App\Jobs\Site\ChangePHPVersion::class);
$site->refresh();
$this->assertEquals('8.2', $site->php_version);
}
public function test_update_v_host(): void
@ -119,27 +114,10 @@ public function test_update_v_host(): void
'server_id' => $this->server->id,
]);
Livewire::test(UpdateVHost::class, ['site' => $site])
->set('vHost', 'test-vhost')
->call('update')
->assertSuccessful();
}
public function test_update_source_control(): void
{
$this->actingAs($this->user);
/** @var \App\Models\SourceControl $gitlab */
$gitlab = \App\Models\SourceControl::factory()->gitlab()->create();
Livewire::test(UpdateSourceControlProvider::class, ['site' => $this->site])
->set('source_control', $gitlab->id)
->call('update')
->assertSuccessful();
$this->site->refresh();
$this->assertEquals($gitlab->id, $this->site->source_control_id);
$this->get(route('servers.sites.settings.vhost', [
'server' => $this->server,
'site' => $site,
]))->assertSessionHasNoErrors();
}
public static function create_data(): array
@ -147,38 +125,38 @@ public static function create_data(): array
return [
[
[
'inputs.type' => SiteType::LARAVEL,
'inputs.domain' => 'example.com',
'inputs.alias' => 'www.example.com',
'inputs.php_version' => '8.2',
'inputs.web_directory' => 'public',
'inputs.repository' => 'test/test',
'inputs.branch' => 'main',
'inputs.composer' => true,
'type' => SiteType::LARAVEL,
'domain' => 'example.com',
'alias' => 'www.example.com',
'php_version' => '8.2',
'web_directory' => 'public',
'repository' => 'test/test',
'branch' => 'main',
'composer' => true,
],
],
[
[
'inputs.type' => SiteType::WORDPRESS,
'inputs.domain' => 'example.com',
'inputs.alias' => 'www.example.com',
'inputs.php_version' => '8.2',
'inputs.title' => 'Example',
'inputs.username' => 'example',
'inputs.email' => 'email@example.com',
'inputs.password' => 'password',
'inputs.database' => 'example',
'inputs.database_user' => 'example',
'inputs.database_password' => 'password',
'type' => SiteType::WORDPRESS,
'domain' => 'example.com',
'alias' => 'www.example.com',
'php_version' => '8.2',
'title' => 'Example',
'username' => 'example',
'email' => 'email@example.com',
'password' => 'password',
'database' => 'example',
'database_user' => 'example',
'database_password' => 'password',
],
],
[
[
'inputs.type' => SiteType::PHP_BLANK,
'inputs.domain' => 'example.com',
'inputs.alias' => 'www.example.com',
'inputs.php_version' => '8.2',
'inputs.web_directory' => 'public',
'type' => SiteType::PHP_BLANK,
'domain' => 'example.com',
'alias' => 'www.example.com',
'php_version' => '8.2',
'web_directory' => 'public',
],
],
];

View File

@ -2,12 +2,10 @@
namespace Tests\Feature;
use App\Http\Livewire\SourceControls\Connect;
use App\Http\Livewire\SourceControls\SourceControlsList;
use App\Models\SourceControl;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Http;
use Livewire\Livewire;
use JsonException;
use Tests\TestCase;
class SourceControlsTest extends TestCase
@ -16,6 +14,8 @@ class SourceControlsTest extends TestCase
/**
* @dataProvider data
*
* @throws JsonException
*/
public function test_connect_provider(string $provider, ?string $customUrl): void
{
@ -23,18 +23,17 @@ public function test_connect_provider(string $provider, ?string $customUrl): voi
Http::fake();
$livewire = Livewire::test(Connect::class)
->set('token', 'token')
->set('name', 'profile')
->set('provider', $provider);
$input = [
'name' => 'test',
'provider' => $provider,
'token' => 'token',
];
if ($customUrl !== null) {
$livewire->set('url', $customUrl);
$input['url'] = $customUrl;
}
$livewire
->call('connect')
->assertSuccessful();
$this->post(route('source-controls.connect'), $input)
->assertSessionHasNoErrors();
$this->assertDatabaseHas('source_controls', [
'provider' => $provider,
@ -44,6 +43,8 @@ public function test_connect_provider(string $provider, ?string $customUrl): voi
/**
* @dataProvider data
*
* @throws JsonException
*/
public function test_delete_provider(string $provider): void
{
@ -55,10 +56,8 @@ public function test_delete_provider(string $provider): void
'profile' => 'test',
]);
Livewire::test(SourceControlsList::class)
->set('deleteId', $sourceControl->id)
->call('delete')
->assertSuccessful();
$this->delete(route('source-controls.delete', $sourceControl->id))
->assertSessionHasNoErrors();
$this->assertDatabaseMissing('source_controls', [
'id' => $sourceControl->id,

View File

@ -2,29 +2,26 @@
namespace Tests\Feature;
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 JsonException;
use Tests\TestCase;
class SshKeysTest extends TestCase
{
use RefreshDatabase;
/**
* @throws JsonException
*/
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();
$this->post(route('ssh-keys.add'), [
'name' => 'test',
'public_key' => 'ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAklOUpkDHrfHY17SbrmTIpNLTGK9Tjom/BWDSUGPl+nafzlHDTYW7hdI4yZ5ew18JH4JW9jbhUFrviQzM7xlELEVf4h9lFX5QVkbPppSwg0cda3Pbv7kOdJ/MTyBlWXFCR+HAo3FXRitBqxiX1nKhXpHAZsMciLq8V6RjsNAQwdsdMFvSlVK/7XAt3FaoJoAsncM1Q9x5+3V0Ww68/eIFmb1zuUFljQJKprrX88XypNDvjYNby6vw/Pb0rwert/EnmZ+AW4OZPnTPI89ZPmVMLuayrD2cE86Z/il8b+gw3r3+1nKatmIkjn2so1d01QraTlMqVSsbxNrRFi9wrf+M7Q== test@test.local',
])->assertSessionHasNoErrors();
}
public function test_get_public_keys_list(): void
@ -35,12 +32,13 @@ public function test_get_public_keys_list(): void
'user_id' => $this->user->id,
]);
Livewire::test(KeysList::class)
->assertSee([
$key->name,
]);
$this->get(route('ssh-keys'))
->assertSee($key->name);
}
/**
* @throws JsonException
*/
public function test_delete_key(): void
{
$this->actingAs($this->user);
@ -49,10 +47,8 @@ public function test_delete_key(): void
'user_id' => $this->user->id,
]);
Livewire::test(KeysList::class)
->set('deleteId', $key->id)
->call('delete')
->assertSuccessful();
$this->delete(route('ssh-keys.delete', $key->id))
->assertSessionHasNoErrors();
$this->assertDatabaseMissing('ssh_keys', [
'id' => $key->id,

View File

@ -4,14 +4,11 @@
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
@ -26,15 +23,23 @@ public function test_see_ssls_list()
'site_id' => $this->site->id,
]);
Livewire::test(SslsList::class, ['site' => $this->site])
->assertSeeText($ssl->type);
$this->get(route('servers.sites.ssl', [
'server' => $this->server,
'site' => $this->site,
]))
->assertOk()
->assertSee($ssl->type);
}
public function test_see_ssls_list_with_no_ssls()
{
$this->actingAs($this->user);
Livewire::test(SslsList::class, ['site' => $this->site])
$this->get(route('servers.sites.ssl', [
'server' => $this->server,
'site' => $this->site,
]))
->assertOk()
->assertSeeText(__("You don't have any SSL certificates yet!"));
}
@ -44,10 +49,12 @@ public function test_create_ssl()
$this->actingAs($this->user);
Livewire::test(CreateSsl::class, ['site' => $this->site])
->set('type', SslType::LETSENCRYPT)
->call('create')
->assertDispatched('created');
$this->post(route('servers.sites.ssl.store', [
'server' => $this->server,
'site' => $this->site,
]), [
'type' => SslType::LETSENCRYPT,
])->assertSessionDoesntHaveErrors();
$this->assertDatabaseHas('ssls', [
'site_id' => $this->site->id,
@ -68,10 +75,11 @@ public function test_delete_ssl()
'site_id' => $this->site->id,
]);
Livewire::test(SslsList::class, ['site' => $this->site])
->set('deleteId', $ssl->id)
->call('delete')
->assertDispatched('confirmed');
$this->delete(route('servers.sites.ssl.destroy', [
'server' => $this->server,
'site' => $this->site,
'ssl' => $ssl,
]))->assertRedirect();
$this->assertDatabaseHas('ssls', [
'id' => $ssl->id,

View File

@ -3,29 +3,29 @@
namespace Tests\Feature;
use App\Enums\StorageProvider;
use App\Http\Livewire\StorageProviders\ConnectProvider;
use App\Http\Livewire\StorageProviders\ProvidersList;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Http;
use Livewire\Livewire;
use JsonException;
use Tests\TestCase;
class StorageProvidersTest extends TestCase
{
use RefreshDatabase;
/**
* @throws JsonException
*/
public function test_connect_dropbox(): void
{
$this->actingAs($this->user);
Http::fake();
Livewire::test(ConnectProvider::class)
->set('provider', StorageProvider::DROPBOX)
->set('name', 'profile')
->set('token', 'token')
->call('connect')
->assertSuccessful();
$this->post(route('storage-providers.connect'), [
'provider' => StorageProvider::DROPBOX,
'name' => 'profile',
'token' => 'token',
])->assertSessionHasNoErrors();
$this->assertDatabaseHas('storage_providers', [
'provider' => StorageProvider::DROPBOX,
@ -42,12 +42,13 @@ public function test_see_providers_list(): void
'provider' => StorageProvider::DROPBOX,
]);
Livewire::test(ProvidersList::class)
->assertSee([
$provider->profile,
]);
$this->get(route('storage-providers'))
->assertSee($provider->profile);
}
/**
* @throws JsonException
*/
public function test_delete_provider(): void
{
$this->actingAs($this->user);
@ -56,10 +57,8 @@ public function test_delete_provider(): void
'user_id' => $this->user->id,
]);
Livewire::test(ProvidersList::class)
->set('deleteId', $provider->id)
->call('delete')
->assertSuccessful();
$this->delete(route('storage-providers.delete', $provider->id))
->assertSessionHasNoErrors();
$this->assertDatabaseMissing('storage_providers', [
'id' => $provider->id,