Files
animethemes-server/tests/Feature/Jobs/Pivot/Wiki/AnimeResourceTest.php
T
paranarimasu 088ea287c5 feat: initial migration to pennant features for feature flags and global site config [incremental] (#573)
* 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
2023-04-23 18:54:34 -05:00

95 lines
2.9 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Feature\Jobs\Pivot\Wiki;
use App\Constants\FeatureConstants;
use App\Events\Pivot\Wiki\AnimeResource\AnimeResourceCreated;
use App\Events\Pivot\Wiki\AnimeResource\AnimeResourceDeleted;
use App\Events\Pivot\Wiki\AnimeResource\AnimeResourceUpdated;
use App\Jobs\SendDiscordNotificationJob;
use App\Models\Wiki\Anime;
use App\Models\Wiki\ExternalResource;
use App\Pivots\Wiki\AnimeResource;
use Illuminate\Support\Facades\Bus;
use Illuminate\Support\Facades\Event;
use Laravel\Pennant\Feature;
use Tests\TestCase;
/**
* Class AnimeResourceTest.
*/
class AnimeResourceTest extends TestCase
{
/**
* When an Anime is attached to a Resource or vice versa, a SendDiscordNotification job shall be dispatched.
*
* @return void
*/
public function testAnimeResourceCreatedSendsDiscordNotification(): void
{
$anime = Anime::factory()->createOne();
$resource = ExternalResource::factory()->createOne();
Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS);
Bus::fake(SendDiscordNotificationJob::class);
Event::fakeExcept(AnimeResourceCreated::class);
$anime->resources()->attach($resource);
Bus::assertDispatched(SendDiscordNotificationJob::class);
}
/**
* When an Anime is detached from a Resource or vice versa, a SendDiscordNotification job shall be dispatched.
*
* @return void
*/
public function testAnimeResourceDeletedSendsDiscordNotification(): void
{
$anime = Anime::factory()->createOne();
$resource = ExternalResource::factory()->createOne();
$anime->resources()->attach($resource);
Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS);
Bus::fake(SendDiscordNotificationJob::class);
Event::fakeExcept(AnimeResourceDeleted::class);
$anime->resources()->detach($resource);
Bus::assertDispatched(SendDiscordNotificationJob::class);
}
/**
* When an Anime Resource pivot is updated, a SendDiscordNotification job shall be dispatched.
*
* @return void
*/
public function testAnimeResourceUpdatedSendsDiscordNotification(): void
{
$anime = Anime::factory()->createOne();
$resource = ExternalResource::factory()->createOne();
$animeResource = AnimeResource::factory()
->for($anime, 'anime')
->for($resource, 'resource')
->createOne();
$changes = AnimeResource::factory()
->for($anime, 'anime')
->for($resource, 'resource')
->makeOne();
Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS);
Bus::fake(SendDiscordNotificationJob::class);
Event::fakeExcept(AnimeResourceUpdated::class);
$animeResource->fill($changes->getAttributes());
$animeResource->save();
Bus::assertDispatched(SendDiscordNotificationJob::class);
}
}