webhook()->create([ 'delivery_url' => 'https://hooks.example.test/kanbangit/core-status', ]); $storedDeliveryUrl = DB::table('notification_actions') ->where('id', $notificationAction->id) ->value('delivery_url'); $this->assertNotSame('https://hooks.example.test/kanbangit/core-status', $storedDeliveryUrl); $this->assertSame('https://hooks.example.test/kanbangit/core-status', $notificationAction->fresh()->delivery_url); $this->assertSame(NotificationEventType::TicketStatusChanged, $notificationAction->fresh()->event_type); $this->assertSame(NotificationChannel::Webhook, $notificationAction->fresh()->channel); $this->assertSame([], $notificationAction->fresh()->channel_configuration); $this->assertSame([], $notificationAction->fresh()->filters ?? []); } /** * Ensure the Discord factory state creates message-driven Discord actions. */ public function test_factory_can_create_discord_notification_actions(): void { $notificationAction = NotificationAction::factory()->discord()->create(); $this->assertSame(NotificationChannel::Discord, $notificationAction->fresh()->channel); $this->assertNotNull($notificationAction->fresh()->message_template); $this->assertStringStartsWith('https://discord.com/api/webhooks/', $notificationAction->fresh()->delivery_url); } /** * Ensure notification actions belong to a project and keep secret URLs out of serialized output. */ public function test_notification_actions_belong_to_projects_and_hide_delivery_urls(): void { $notificationAction = NotificationAction::factory()->create(); $resource = (new NotificationActionResource($notificationAction->fresh())) ->toArray(Request::create('/')); $this->assertTrue($notificationAction->project()->exists()); $this->assertTrue($notificationAction->project->is($notificationAction->fresh()->project)); $this->assertArrayNotHasKey('delivery_url', $notificationAction->fresh()->toArray()); $this->assertArrayNotHasKey('delivery_url', $resource); $this->assertTrue($resource['has_delivery_url']); $this->assertSame([], $resource['filters']); } }