Skip to content

Commit

Permalink
Support disabling slack route dynamically when using `SlackWebhookCha…
Browse files Browse the repository at this point in the history
…nnel` (#87)

* Support disabling slack route dynamically

* Fix formatting

* Add test case
  • Loading branch information
marijoo authored Jan 6, 2024
1 parent 4841ab6 commit bac7511
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/SlackNotificationRouterChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ public function send($notifiable, Notification $notification)
{
$route = $notifiable->routeNotificationFor('slack', $notification);

if ($route === false) {
return;
}

return $this->determineChannel($route)->send($notifiable, $notification);
}

Expand Down
16 changes: 16 additions & 0 deletions tests/SlackNotificationRouterChannelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,22 @@ public function it_routes_the_notification_to_the_web_api_channel_when_the_notif

$channel->send(new SlackChannelTestNotifiable('#general'), new SlackChannelTestNotification());
}

/** @test */
public function it_stops_sending_when_the_notifiable_route_is_false(): void
{
$app = new Container();
$app->bind(SlackWebhookChannel::class, fn () => new FakeSlackChannel(function () {
$this->fail('The Slack Webhook Channel should not have been called.');
}));
$app->bind(SlackWebApiChannel::class, fn () => new FakeSlackChannel(function () {
$this->fail('The Slack WebAPI Channel should not have been called.');
}));

$channel = new SlackNotificationRouterChannel($app);

$this->assertEquals(null, $channel->send(new SlackChannelTestNotifiable(false), new SlackChannelTestNotification()));
}
}

class FakeSlackChannel
Expand Down

0 comments on commit bac7511

Please sign in to comment.