Files
animethemes-server/tests/Feature/Jobs/Pivot/Wiki/ArtistMemberTest.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

94 lines
2.8 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Feature\Jobs\Pivot\Wiki;
use App\Constants\FeatureConstants;
use App\Events\Pivot\Wiki\ArtistMember\ArtistMemberCreated;
use App\Events\Pivot\Wiki\ArtistMember\ArtistMemberDeleted;
use App\Events\Pivot\Wiki\ArtistMember\ArtistMemberUpdated;
use App\Jobs\SendDiscordNotificationJob;
use App\Models\Wiki\Artist;
use App\Pivots\Wiki\ArtistMember;
use Illuminate\Support\Facades\Bus;
use Illuminate\Support\Facades\Event;
use Laravel\Pennant\Feature;
use Tests\TestCase;
/**
* Class ArtistMemberTest.
*/
class ArtistMemberTest extends TestCase
{
/**
* When an Artist is attached to a Member or vice versa, a SendDiscordNotification job shall be dispatched.
*
* @return void
*/
public function testArtistMemberCreatedSendsDiscordNotification(): void
{
$artist = Artist::factory()->createOne();
$member = Artist::factory()->createOne();
Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS);
Bus::fake(SendDiscordNotificationJob::class);
Event::fakeExcept(ArtistMemberCreated::class);
$artist->members()->attach($member);
Bus::assertDispatched(SendDiscordNotificationJob::class);
}
/**
* When an Artist is detached from a Member or vice versa, a SendDiscordNotification job shall be dispatched.
*
* @return void
*/
public function testArtistMemberDeletedSendsDiscordNotification(): void
{
$artist = Artist::factory()->createOne();
$member = Artist::factory()->createOne();
$artist->members()->attach($member);
Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS);
Bus::fake(SendDiscordNotificationJob::class);
Event::fakeExcept(ArtistMemberDeleted::class);
$artist->members()->detach($member);
Bus::assertDispatched(SendDiscordNotificationJob::class);
}
/**
* When an Artist Member pivot is updated, a SendDiscordNotification job shall be dispatched.
*
* @return void
*/
public function testArtistMemberUpdatedSendsDiscordNotification(): void
{
$artist = Artist::factory()->createOne();
$member = Artist::factory()->createOne();
$artistMember = ArtistMember::factory()
->for($artist, 'artist')
->for($member, 'member')
->createOne();
$changes = ArtistMember::factory()
->for($artist, 'artist')
->for($member, 'member')
->makeOne();
Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS);
Bus::fake(SendDiscordNotificationJob::class);
Event::fakeExcept(ArtistMemberUpdated::class);
$artistMember->fill($changes->getAttributes());
$artistMember->save();
Bus::assertDispatched(SendDiscordNotificationJob::class);
}
}