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.
This commit is contained in:
@@ -31,6 +31,11 @@ class DiscordReleaseNotification implements ShouldQueue
|
|||||||
*/
|
*/
|
||||||
public function handle(): void
|
public function handle(): void
|
||||||
{
|
{
|
||||||
|
// Discord notifications must only ever be sent in production.
|
||||||
|
if (! app()->isProduction()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
switch ($this->messageType) {
|
switch ($this->messageType) {
|
||||||
case 'release':
|
case 'release':
|
||||||
DiscordAlert::message('<@&868457842250764289> (´• ω •`)ノ New **4k** Release! Check it out here: https://hstream.moe/hentai/'.$this->slug);
|
DiscordAlert::message('<@&868457842250764289> (´• ω •`)ノ New **4k** Release! Check it out here: https://hstream.moe/hentai/'.$this->slug);
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Unit;
|
||||||
|
|
||||||
|
use App\Jobs\DiscordReleaseNotification;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class DiscordReleaseNotificationTest extends TestCase
|
||||||
|
{
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
Http::fake();
|
||||||
|
config([
|
||||||
|
'discord-alerts.webhook_urls.default' => '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');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user