actingAs($this->user); $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() ->where('provider', NotificationChannel::EMAIL) ->first(); $this->assertEquals('email@example.com', $channel->data['email']); $this->assertTrue($channel->connected); } /** * @throws JsonException */ public function test_add_slack_channel(): void { $this->actingAs($this->user); Http::fake(); $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() ->where('provider', NotificationChannel::SLACK) ->first(); $this->assertEquals('https://hooks.slack.com/services/123/token', $channel->data['webhook_url']); $this->assertTrue($channel->connected); } /** * @throws JsonException */ public function test_add_discord_channel(): void { $this->actingAs($this->user); Http::fake(); $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() ->where('provider', NotificationChannel::DISCORD) ->first(); $this->assertEquals('https://discord.com/api/webhooks/123/token', $channel->data['webhook_url']); $this->assertTrue($channel->connected); } /* * @TODO fix json comparison */ /** * @throws JsonException */ public function test_add_telegram_channel(): void { $this->actingAs($this->user); Http::fake(); $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() ->where('provider', NotificationChannel::TELEGRAM) ->first(); $this->assertEquals('123', $channel->data['chat_id']); $this->assertEquals('token', $channel->data['bot_token']); $this->assertTrue($channel->connected); } public function test_see_channels_list(): void { $this->actingAs($this->user); $channel = \App\Models\NotificationChannel::factory()->create(); $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(); $this->delete(route('notification-channels.delete', $channel->id)) ->assertSessionHasNoErrors(); $this->assertDatabaseMissing('notification_channels', [ 'id' => $channel->id, ]); } }