mirror of
https://github.com/AnimeThemes/animethemes-server.git
synced 2026-07-26 08:44:30 +02:00
* feat: initial commit for feature management * style: fix StyleCI findings * fix(api): prohibit features of nonnull scope from API & fix(admin): wrong translate key * style: fix Static Analysis error
97 lines
2.9 KiB
PHP
97 lines
2.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Feature\Jobs\Admin;
|
|
|
|
use App\Constants\FeatureConstants;
|
|
use App\Events\Admin\Announcement\AnnouncementCreated;
|
|
use App\Events\Admin\Announcement\AnnouncementDeleted;
|
|
use App\Events\Admin\Announcement\AnnouncementRestored;
|
|
use App\Events\Admin\Announcement\AnnouncementUpdated;
|
|
use App\Jobs\SendDiscordNotificationJob;
|
|
use App\Models\Admin\Announcement;
|
|
use Illuminate\Support\Facades\Bus;
|
|
use Illuminate\Support\Facades\Event;
|
|
use Laravel\Pennant\Feature;
|
|
use Tests\TestCase;
|
|
|
|
/**
|
|
* Class AnnouncementTest.
|
|
*/
|
|
class AnnouncementTest extends TestCase
|
|
{
|
|
/**
|
|
* When an announcement is created, a SendDiscordNotification job shall be dispatched.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function testAnnouncementCreatedSendsDiscordNotification(): void
|
|
{
|
|
Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS);
|
|
Bus::fake(SendDiscordNotificationJob::class);
|
|
Event::fakeExcept(AnnouncementCreated::class);
|
|
|
|
Announcement::factory()->createOne();
|
|
|
|
Bus::assertDispatched(SendDiscordNotificationJob::class);
|
|
}
|
|
|
|
/**
|
|
* When an announcement is deleted, a SendDiscordNotification job shall be dispatched.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function testAnnouncementDeletedSendsDiscordNotification(): void
|
|
{
|
|
$announcement = Announcement::factory()->createOne();
|
|
|
|
Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS);
|
|
Bus::fake(SendDiscordNotificationJob::class);
|
|
Event::fakeExcept(AnnouncementDeleted::class);
|
|
|
|
$announcement->delete();
|
|
|
|
Bus::assertDispatched(SendDiscordNotificationJob::class);
|
|
}
|
|
|
|
/**
|
|
* When an announcement is restored, a SendDiscordNotification job shall be dispatched.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function testAnnouncementRestoredSendsDiscordNotification(): void
|
|
{
|
|
$announcement = Announcement::factory()->createOne();
|
|
|
|
Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS);
|
|
Bus::fake(SendDiscordNotificationJob::class);
|
|
Event::fakeExcept(AnnouncementRestored::class);
|
|
|
|
$announcement->restore();
|
|
|
|
Bus::assertDispatched(SendDiscordNotificationJob::class);
|
|
}
|
|
|
|
/**
|
|
* When an announcement is updated, a SendDiscordNotification job shall be dispatched.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function testAnnouncementUpdatedSendsDiscordNotification(): void
|
|
{
|
|
$announcement = Announcement::factory()->createOne();
|
|
|
|
Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS);
|
|
Bus::fake(SendDiscordNotificationJob::class);
|
|
Event::fakeExcept(AnnouncementUpdated::class);
|
|
|
|
$changes = Announcement::factory()->makeOne();
|
|
|
|
$announcement->fill($changes->getAttributes());
|
|
$announcement->save();
|
|
|
|
Bus::assertDispatched(SendDiscordNotificationJob::class);
|
|
}
|
|
}
|