From 2076517ebdd02bf695f9921a05b38b6d17ff596e Mon Sep 17 00:00:00 2001 From: w33b Date: Sat, 8 Aug 2026 12:51:22 +0200 Subject: [PATCH] fix(discord): only send notifications in production Prevent Discord release notifications from being sent in non-production environments, avoiding accidental notifications during development and testing. Added unit tests to verify the behavior. --- app/Jobs/DiscordReleaseNotification.php | 5 +++ tests/Unit/DiscordReleaseNotificationTest.php | 38 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 tests/Unit/DiscordReleaseNotificationTest.php diff --git a/app/Jobs/DiscordReleaseNotification.php b/app/Jobs/DiscordReleaseNotification.php index b3b3b6a..73c0e9e 100644 --- a/app/Jobs/DiscordReleaseNotification.php +++ b/app/Jobs/DiscordReleaseNotification.php @@ -31,6 +31,11 @@ class DiscordReleaseNotification implements ShouldQueue */ public function handle(): void { + // Discord notifications must only ever be sent in production. + if (! app()->isProduction()) { + return; + } + switch ($this->messageType) { case 'release': DiscordAlert::message('<@&868457842250764289> (´• ω •`)ノ New **4k** Release! Check it out here: https://hstream.moe/hentai/'.$this->slug); diff --git a/tests/Unit/DiscordReleaseNotificationTest.php b/tests/Unit/DiscordReleaseNotificationTest.php new file mode 100644 index 0000000..738f79e --- /dev/null +++ b/tests/Unit/DiscordReleaseNotificationTest.php @@ -0,0 +1,38 @@ + 'https://discord.com/api/webhooks/test/123', + ]); + } + + public function test_it_does_not_send_outside_production(): void + { + (new DiscordReleaseNotification('some-slug', 'release'))->handle(); + + Http::assertNothingSent(); + } + + public function test_it_sends_in_production(): void + { + app()->instance('env', 'production'); + + (new DiscordReleaseNotification('some-slug', 'release'))->handle(); + + Http::assertSent(function ($request) { + return str_contains($request->url(), 'https://discord.com/api/webhooks/test/123'); + }); + } +}