migrating tests (Metrics, NotificationChannels, PHP, Profile and Projects)

This commit is contained in:
Saeed Vaziry
2024-10-10 23:24:07 +02:00
parent 93cee92568
commit 7086e84c3c
16 changed files with 292 additions and 212 deletions

View File

@ -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,