Files
animethemes-server/tests/Feature/Jobs/Pivot/Wiki/ArtistResourceTest.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
3.0 KiB
PHP

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