mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-02 22:46:16 +00:00
migrating tests (Metrics, NotificationChannels, PHP, Profile and Projects)
This commit is contained in:
@ -4,7 +4,9 @@
|
||||
|
||||
use App\Enums\ServiceStatus;
|
||||
use App\Models\Service;
|
||||
use App\Web\Pages\Servers\Metrics\Index;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
class MetricsTest extends TestCase
|
||||
@ -23,7 +25,7 @@ public function test_visit_metrics(): void
|
||||
'status' => ServiceStatus::READY,
|
||||
]);
|
||||
|
||||
$this->get(route('servers.metrics', ['server' => $this->server]))
|
||||
$this->get(Index::getUrl(['server' => $this->server]))
|
||||
->assertSuccessful()
|
||||
->assertSee('CPU Load')
|
||||
->assertSee('Memory Usage')
|
||||
@ -34,8 +36,8 @@ public function test_cannot_visit_metrics(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$this->get(route('servers.metrics', ['server' => $this->server]))
|
||||
->assertNotFound();
|
||||
$this->get(Index::getUrl(['server' => $this->server]))
|
||||
->assertForbidden();
|
||||
}
|
||||
|
||||
public function test_update_data_retention(): void
|
||||
@ -50,14 +52,18 @@ public function test_update_data_retention(): void
|
||||
'status' => ServiceStatus::READY,
|
||||
]);
|
||||
|
||||
$this->post(route('servers.metrics.settings', ['server' => $this->server]), [
|
||||
'data_retention' => 30,
|
||||
])->assertSessionHas('toast.type', 'success');
|
||||
Livewire::test(Index::class, [
|
||||
'server' => $this->server,
|
||||
])
|
||||
->callAction('data-retention', [
|
||||
'data_retention' => 365,
|
||||
])
|
||||
->assertSuccessful();
|
||||
|
||||
$this->assertDatabaseHas('services', [
|
||||
'server_id' => $this->server->id,
|
||||
'type' => 'monitoring',
|
||||
'type_data->data_retention' => 30,
|
||||
'type_data->data_retention' => 365,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -3,9 +3,12 @@
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Enums\NotificationChannel;
|
||||
use App\Web\Pages\Settings\NotificationChannels\Index;
|
||||
use App\Web\Pages\Settings\NotificationChannels\Widgets\NotificationChannelsList;
|
||||
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
|
||||
@ -17,12 +20,14 @@ public function test_add_email_channel(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$this->post(route('settings.notification-channels.add'), [
|
||||
'provider' => NotificationChannel::EMAIL,
|
||||
'email' => 'email@example.com',
|
||||
'label' => 'Email',
|
||||
'global' => 1,
|
||||
])->assertSessionDoesntHaveErrors();
|
||||
Livewire::test(Index::class)
|
||||
->callAction('add', [
|
||||
'provider' => NotificationChannel::EMAIL,
|
||||
'email' => 'email@example.com',
|
||||
'label' => 'Email',
|
||||
'global' => true,
|
||||
])
|
||||
->assertSuccessful();
|
||||
|
||||
/** @var \App\Models\NotificationChannel $channel */
|
||||
$channel = \App\Models\NotificationChannel::query()
|
||||
@ -42,11 +47,14 @@ public function test_cannot_add_email_channel(): void
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$this->post(route('settings.notification-channels.add'), [
|
||||
'provider' => NotificationChannel::EMAIL,
|
||||
'email' => 'email@example.com',
|
||||
'label' => 'Email',
|
||||
])->assertSessionHasErrors();
|
||||
Livewire::test(Index::class)
|
||||
->callAction('add', [
|
||||
'provider' => NotificationChannel::EMAIL,
|
||||
'email' => 'email@example.com',
|
||||
'label' => 'Email',
|
||||
'global' => true,
|
||||
])
|
||||
->assertNotified('Could not connect! Make sure you configured `.env` file correctly.');
|
||||
|
||||
/** @var \App\Models\NotificationChannel $channel */
|
||||
$channel = \App\Models\NotificationChannel::query()
|
||||
@ -63,11 +71,13 @@ public function test_add_slack_channel(): void
|
||||
|
||||
Http::fake();
|
||||
|
||||
$this->post(route('settings.notification-channels.add'), [
|
||||
'provider' => NotificationChannel::SLACK,
|
||||
'webhook_url' => 'https://hooks.slack.com/services/123/token',
|
||||
'label' => 'Slack',
|
||||
])->assertSessionDoesntHaveErrors();
|
||||
Livewire::test(Index::class)
|
||||
->callAction('add', [
|
||||
'provider' => NotificationChannel::SLACK,
|
||||
'webhook_url' => 'https://hooks.slack.com/services/123/token',
|
||||
'label' => 'Slack',
|
||||
])
|
||||
->assertSuccessful();
|
||||
|
||||
/** @var \App\Models\NotificationChannel $channel */
|
||||
$channel = \App\Models\NotificationChannel::query()
|
||||
@ -86,11 +96,13 @@ public function test_cannot_add_slack_channel(): void
|
||||
'slack.com/*' => Http::response(['ok' => false], 401),
|
||||
]);
|
||||
|
||||
$this->post(route('settings.notification-channels.add'), [
|
||||
'provider' => NotificationChannel::SLACK,
|
||||
'webhook_url' => 'https://hooks.slack.com/services/123/token',
|
||||
'label' => 'Slack',
|
||||
])->assertSessionHasErrors();
|
||||
Livewire::test(Index::class)
|
||||
->callAction('add', [
|
||||
'provider' => NotificationChannel::SLACK,
|
||||
'webhook_url' => 'https://hooks.slack.com/services/123/token',
|
||||
'label' => 'Slack',
|
||||
])
|
||||
->assertNotified('Could not connect');
|
||||
|
||||
/** @var \App\Models\NotificationChannel $channel */
|
||||
$channel = \App\Models\NotificationChannel::query()
|
||||
@ -106,11 +118,13 @@ public function test_add_discord_channel(): void
|
||||
|
||||
Http::fake();
|
||||
|
||||
$this->post(route('settings.notification-channels.add'), [
|
||||
'provider' => NotificationChannel::DISCORD,
|
||||
'webhook_url' => 'https://discord.com/api/webhooks/123/token',
|
||||
'label' => 'Discord',
|
||||
])->assertSessionDoesntHaveErrors();
|
||||
Livewire::test(Index::class)
|
||||
->callAction('add', [
|
||||
'provider' => NotificationChannel::DISCORD,
|
||||
'webhook_url' => 'https://discord.com/api/webhooks/123/token',
|
||||
'label' => 'Discord',
|
||||
])
|
||||
->assertSuccessful();
|
||||
|
||||
/** @var \App\Models\NotificationChannel $channel */
|
||||
$channel = \App\Models\NotificationChannel::query()
|
||||
@ -129,11 +143,13 @@ public function test_cannot_add_discord_channel(): void
|
||||
'discord.com/*' => Http::response(['ok' => false], 401),
|
||||
]);
|
||||
|
||||
$this->post(route('settings.notification-channels.add'), [
|
||||
'provider' => NotificationChannel::DISCORD,
|
||||
'webhook_url' => 'https://discord.com/api/webhooks/123/token',
|
||||
'label' => 'Discord',
|
||||
])->assertSessionHasErrors();
|
||||
Livewire::test(Index::class)
|
||||
->callAction('add', [
|
||||
'provider' => NotificationChannel::DISCORD,
|
||||
'webhook_url' => 'https://discord.com/api/webhooks/123/token',
|
||||
'label' => 'Discord',
|
||||
])
|
||||
->assertNotified('Could not connect');
|
||||
|
||||
/** @var \App\Models\NotificationChannel $channel */
|
||||
$channel = \App\Models\NotificationChannel::query()
|
||||
@ -149,12 +165,14 @@ public function test_add_telegram_channel(): void
|
||||
|
||||
Http::fake();
|
||||
|
||||
$this->post(route('settings.notification-channels.add'), [
|
||||
'provider' => NotificationChannel::TELEGRAM,
|
||||
'bot_token' => 'token',
|
||||
'chat_id' => '123',
|
||||
'label' => 'Telegram',
|
||||
])->assertSessionDoesntHaveErrors();
|
||||
Livewire::test(Index::class)
|
||||
->callAction('add', [
|
||||
'provider' => NotificationChannel::TELEGRAM,
|
||||
'bot_token' => 'token',
|
||||
'chat_id' => '123',
|
||||
'label' => 'Telegram',
|
||||
])
|
||||
->assertSuccessful();
|
||||
|
||||
/** @var \App\Models\NotificationChannel $channel */
|
||||
$channel = \App\Models\NotificationChannel::query()
|
||||
@ -174,12 +192,14 @@ public function test_cannot_add_telegram_channel(): void
|
||||
'api.telegram.org/*' => Http::response(['ok' => false], 401),
|
||||
]);
|
||||
|
||||
$this->post(route('settings.notification-channels.add'), [
|
||||
'provider' => NotificationChannel::TELEGRAM,
|
||||
'bot_token' => 'token',
|
||||
'chat_id' => '123',
|
||||
'label' => 'Telegram',
|
||||
])->assertSessionHasErrors();
|
||||
Livewire::test(Index::class)
|
||||
->callAction('add', [
|
||||
'provider' => NotificationChannel::TELEGRAM,
|
||||
'bot_token' => 'token',
|
||||
'chat_id' => '123',
|
||||
'label' => 'Telegram',
|
||||
])
|
||||
->assertNotified('Could not connect');
|
||||
|
||||
/** @var \App\Models\NotificationChannel $channel */
|
||||
$channel = \App\Models\NotificationChannel::query()
|
||||
@ -193,11 +213,12 @@ public function test_see_channels_list(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
/** @var \App\Models\NotificationChannel $channel */
|
||||
$channel = \App\Models\NotificationChannel::factory()->create();
|
||||
|
||||
$this->get(route('settings.notification-channels'))
|
||||
$this->get(Index::getUrl())
|
||||
->assertSuccessful()
|
||||
->assertSee($channel->provider);
|
||||
->assertSee($channel->label);
|
||||
}
|
||||
|
||||
public function test_delete_channel(): void
|
||||
@ -206,8 +227,9 @@ public function test_delete_channel(): void
|
||||
|
||||
$channel = \App\Models\NotificationChannel::factory()->create();
|
||||
|
||||
$this->delete(route('settings.notification-channels.delete', $channel->id))
|
||||
->assertSessionDoesntHaveErrors();
|
||||
Livewire::test(NotificationChannelsList::class)
|
||||
->callTableAction('delete', $channel->id)
|
||||
->assertSuccessful();
|
||||
|
||||
$this->assertDatabaseMissing('notification_channels', [
|
||||
'id' => $channel->id,
|
||||
|
@ -6,7 +6,10 @@
|
||||
use App\Enums\ServiceStatus;
|
||||
use App\Facades\SSH;
|
||||
use App\Models\Service;
|
||||
use App\Web\Pages\Servers\PHP\Index;
|
||||
use App\Web\Pages\Servers\PHP\Widgets\PHPList;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
class PHPTest extends TestCase
|
||||
@ -19,10 +22,11 @@ public function test_install_new_php(): void
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$this->post(route('servers.php.install', [
|
||||
'server' => $this->server,
|
||||
'version' => '8.1',
|
||||
]))->assertSessionDoesntHaveErrors();
|
||||
Livewire::test(Index::class, ['server' => $this->server])
|
||||
->callAction('install', [
|
||||
'version' => '8.1',
|
||||
])
|
||||
->assertSuccessful();
|
||||
|
||||
$this->assertDatabaseHas('services', [
|
||||
'server_id' => $this->server->id,
|
||||
@ -52,26 +56,17 @@ public function test_uninstall_php(): void
|
||||
]);
|
||||
$php->save();
|
||||
|
||||
$this->delete(route('servers.php.uninstall', [
|
||||
Livewire::test(PHPList::class, [
|
||||
'server' => $this->server,
|
||||
'version' => '8.1',
|
||||
]))->assertSessionDoesntHaveErrors();
|
||||
])
|
||||
->callTableAction('uninstall', $php->id)
|
||||
->assertSuccessful();
|
||||
|
||||
$this->assertDatabaseMissing('services', [
|
||||
'id' => $php->id,
|
||||
]);
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
SSH::fake();
|
||||
@ -87,12 +82,14 @@ public function test_change_default_php_cli(): void
|
||||
'name' => 'php',
|
||||
'version' => '8.1',
|
||||
'status' => ServiceStatus::READY,
|
||||
'is_default' => false,
|
||||
]);
|
||||
|
||||
$this->post(route('servers.php.default-cli', [
|
||||
Livewire::test(PHPList::class, [
|
||||
'server' => $this->server,
|
||||
'version' => '8.1',
|
||||
]))->assertSessionDoesntHaveErrors();
|
||||
])
|
||||
->callTableAction('default-php-cli', $php->id)
|
||||
->assertSuccessful();
|
||||
|
||||
$php->refresh();
|
||||
|
||||
@ -105,38 +102,19 @@ public function test_install_extension(): void
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$this->post(route('servers.php.install-extension', [
|
||||
Livewire::test(PHPList::class, [
|
||||
'server' => $this->server,
|
||||
'version' => '8.2',
|
||||
'extension' => 'gmp',
|
||||
]))->assertSessionDoesntHaveErrors();
|
||||
])
|
||||
->callTableAction('install-extension', $this->server->php()->id, [
|
||||
'extension' => 'gmp',
|
||||
])
|
||||
->assertSuccessful();
|
||||
|
||||
$php = $this->server->php('8.2');
|
||||
|
||||
$this->assertContains('gmp', $php->type_data['extensions']);
|
||||
}
|
||||
|
||||
public function test_extension_already_installed(): void
|
||||
{
|
||||
SSH::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();
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider php_ini_data
|
||||
*/
|
||||
@ -146,31 +124,13 @@ public function test_get_php_ini(string $version, string $type): void
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$this->get(route('servers.php.get-ini', [
|
||||
Livewire::test(PHPList::class, [
|
||||
'server' => $this->server,
|
||||
'version' => $version,
|
||||
'type' => $type,
|
||||
]))->assertSessionHas('ini');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider php_ini_data
|
||||
*/
|
||||
public function test_update_php_ini(string $version, string $type): void
|
||||
{
|
||||
SSH::fake();
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$this->post(route('servers.php.update-ini', [
|
||||
'server' => $this->server,
|
||||
'version' => $version,
|
||||
'type' => $type,
|
||||
'ini' => 'new ini',
|
||||
]))
|
||||
->assertSessionDoesntHaveErrors()
|
||||
->assertSessionHas('toast.type', 'success')
|
||||
->assertSessionHas('toast.message', __('PHP ini (:type) updated!', ['type' => $type]));
|
||||
])
|
||||
->callTableAction('php-ini-'.$type, $this->server->php()->id, [
|
||||
'ini' => 'new-ini',
|
||||
])
|
||||
->assertSuccessful();
|
||||
}
|
||||
|
||||
public static function php_ini_data(): array
|
||||
|
@ -2,8 +2,12 @@
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Web\Pages\Settings\Profile\Index;
|
||||
use App\Web\Pages\Settings\Profile\Widgets\ProfileInformation;
|
||||
use App\Web\Pages\Settings\Profile\Widgets\UpdatePassword;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ProfileTest extends TestCase
|
||||
@ -15,7 +19,7 @@ public function test_profile_page_is_displayed(): void
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$this
|
||||
->get(route('profile'))
|
||||
->get(Index::getUrl())
|
||||
->assertSuccessful()
|
||||
->assertSee('Profile Information')
|
||||
->assertSee('Update Password')
|
||||
@ -26,11 +30,13 @@ public function test_profile_information_can_be_updated(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$this->post(route('profile.info'), [
|
||||
'name' => 'Test',
|
||||
'email' => 'test@example.com',
|
||||
'timezone' => 'Europe/Berlin',
|
||||
]);
|
||||
Livewire::test(ProfileInformation::class)
|
||||
->fill([
|
||||
'name' => 'Test',
|
||||
'email' => 'test@example.com',
|
||||
'timezone' => 'Europe/Berlin',
|
||||
])
|
||||
->call('submit');
|
||||
|
||||
$this->user->refresh();
|
||||
|
||||
@ -43,11 +49,13 @@ 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',
|
||||
]);
|
||||
Livewire::test(UpdatePassword::class)
|
||||
->fill([
|
||||
'current_password' => 'password',
|
||||
'password' => 'new-password',
|
||||
'password_confirmation' => 'new-password',
|
||||
])
|
||||
->call('submit');
|
||||
|
||||
$this->assertTrue(Hash::check('new-password', $this->user->refresh()->password));
|
||||
}
|
||||
@ -56,10 +64,13 @@ public function test_correct_password_must_be_provided_to_update_password(): voi
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$this->post(route('profile.password'), [
|
||||
'current_password' => 'wrong-password',
|
||||
'password' => 'new-password',
|
||||
'password_confirmation' => 'new-password',
|
||||
])->assertSessionHasErrors('current_password');
|
||||
Livewire::test(UpdatePassword::class)
|
||||
->fill([
|
||||
'current_password' => 'wrong-password',
|
||||
'password' => 'new-password',
|
||||
'password_confirmation' => 'new-password',
|
||||
])
|
||||
->call('submit')
|
||||
->assertHasErrors('current_password');
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,11 @@
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\Project;
|
||||
use App\Web\Pages\Settings\Projects\Index;
|
||||
use App\Web\Pages\Settings\Projects\Settings;
|
||||
use App\Web\Pages\Settings\Projects\Widgets\UpdateProject;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ProjectsTest extends TestCase
|
||||
@ -14,9 +18,11 @@ public function test_create_project(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$this->post(route('settings.projects.create'), [
|
||||
'name' => 'test',
|
||||
])->assertSessionDoesntHaveErrors();
|
||||
Livewire::test(Index::class)
|
||||
->callAction('create', [
|
||||
'name' => 'test',
|
||||
])
|
||||
->assertSuccessful();
|
||||
|
||||
$this->assertDatabaseHas('projects', [
|
||||
'name' => 'test',
|
||||
@ -31,7 +37,7 @@ public function test_see_projects_list(): void
|
||||
|
||||
$this->user->projects()->attach($project);
|
||||
|
||||
$this->get(route('settings.projects'))
|
||||
$this->get(Index::getUrl())
|
||||
->assertSuccessful()
|
||||
->assertSee($project->name);
|
||||
}
|
||||
@ -44,8 +50,11 @@ public function test_delete_project(): void
|
||||
|
||||
$this->user->projects()->attach($project);
|
||||
|
||||
$this->delete(route('settings.projects.delete', $project))
|
||||
->assertSessionDoesntHaveErrors();
|
||||
Livewire::test(Settings::class, [
|
||||
'project' => $project,
|
||||
])
|
||||
->callAction('delete')
|
||||
->assertSuccessful();
|
||||
|
||||
$this->assertDatabaseMissing('projects', [
|
||||
'id' => $project->id,
|
||||
@ -60,9 +69,14 @@ public function test_edit_project(): void
|
||||
|
||||
$this->user->projects()->attach($project);
|
||||
|
||||
$this->post(route('settings.projects.update', $project), [
|
||||
'name' => 'new-name',
|
||||
])->assertSessionDoesntHaveErrors();
|
||||
Livewire::test(UpdateProject::class, [
|
||||
'project' => $project,
|
||||
])
|
||||
->fill([
|
||||
'name' => 'new-name',
|
||||
])
|
||||
->call('submit')
|
||||
->assertSuccessful();
|
||||
|
||||
$this->assertDatabaseHas('projects', [
|
||||
'id' => $project->id,
|
||||
@ -74,11 +88,14 @@ public function test_cannot_delete_last_project(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$this->delete(route('settings.projects.delete', [
|
||||
Livewire::test(Settings::class, [
|
||||
'project' => $this->user->currentProject,
|
||||
]))
|
||||
->assertSessionDoesntHaveErrors()
|
||||
->assertSessionHas('toast.type', 'error')
|
||||
->assertSessionHas('toast.message', 'Cannot delete the last project.');
|
||||
])
|
||||
->callAction('delete')
|
||||
->assertNotified('Cannot delete the last project.');
|
||||
|
||||
$this->assertDatabaseHas('projects', [
|
||||
'id' => $this->user->currentProject->id,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user