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

63 lines
1.8 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Feature\Jobs\Pivot\Wiki;
use App\Constants\FeatureConstants;
use App\Events\Pivot\Wiki\ArtistImage\ArtistImageCreated;
use App\Events\Pivot\Wiki\ArtistImage\ArtistImageDeleted;
use App\Jobs\SendDiscordNotificationJob;
use App\Models\Wiki\Artist;
use App\Models\Wiki\Image;
use Illuminate\Support\Facades\Bus;
use Illuminate\Support\Facades\Event;
use Laravel\Pennant\Feature;
use Tests\TestCase;
/**
* Class ArtistImageTest.
*/
class ArtistImageTest extends TestCase
{
/**
* When an Artist is attached to an Image or vice versa, a SendDiscordNotification job shall be dispatched.
*
* @return void
*/
public function testArtistImageCreatedSendsDiscordNotification(): void
{
$artist = Artist::factory()->createOne();
$image = Image::factory()->createOne();
Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS);
Bus::fake(SendDiscordNotificationJob::class);
Event::fakeExcept(ArtistImageCreated::class);
$artist->images()->attach($image);
Bus::assertDispatched(SendDiscordNotificationJob::class);
}
/**
* When an Artist is detached from an Image or vice versa, a SendDiscordNotification job shall be dispatched.
*
* @return void
*/
public function testArtistImageDeletedSendsDiscordNotification(): void
{
$artist = Artist::factory()->createOne();
$image = Image::factory()->createOne();
$artist->images()->attach($image);
Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS);
Bus::fake(SendDiscordNotificationJob::class);
Event::fakeExcept(ArtistImageDeleted::class);
$artist->images()->detach($image);
Bus::assertDispatched(SendDiscordNotificationJob::class);
}
}