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

108 lines
3.0 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Feature\Jobs\Wiki\Anime;
use App\Constants\FeatureConstants;
use App\Events\Wiki\Anime\Synonym\SynonymCreated;
use App\Events\Wiki\Anime\Synonym\SynonymDeleted;
use App\Events\Wiki\Anime\Synonym\SynonymRestored;
use App\Events\Wiki\Anime\Synonym\SynonymUpdated;
use App\Jobs\SendDiscordNotificationJob;
use App\Models\Wiki\Anime;
use App\Models\Wiki\Anime\AnimeSynonym;
use Illuminate\Support\Facades\Bus;
use Illuminate\Support\Facades\Event;
use Laravel\Pennant\Feature;
use Tests\TestCase;
/**
* Class SynonymTest.
*/
class SynonymTest extends TestCase
{
/**
* When a synonym is created, a SendDiscordNotification job shall be dispatched.
*
* @return void
*/
public function testSynonymCreatedSendsDiscordNotification(): void
{
$anime = Anime::factory()->createOne();
Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS);
Bus::fake(SendDiscordNotificationJob::class);
Event::fakeExcept(SynonymCreated::class);
AnimeSynonym::factory()->for($anime)->createOne();
Bus::assertDispatched(SendDiscordNotificationJob::class);
}
/**
* When a synonym is deleted, a SendDiscordNotification job shall be dispatched.
*
* @return void
*/
public function testSynonymDeletedSendsDiscordNotification(): void
{
$synonym = AnimeSynonym::factory()
->for(Anime::factory())
->createOne();
Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS);
Bus::fake(SendDiscordNotificationJob::class);
Event::fakeExcept(SynonymDeleted::class);
$synonym->delete();
Bus::assertDispatched(SendDiscordNotificationJob::class);
}
/**
* When a synonym is restored, a SendDiscordNotification job shall be dispatched.
*
* @return void
*/
public function testSynonymRestoredSendsDiscordNotification(): void
{
$synonym = AnimeSynonym::factory()
->for(Anime::factory())
->createOne();
Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS);
Bus::fake(SendDiscordNotificationJob::class);
Event::fakeExcept(SynonymRestored::class);
$synonym->restore();
Bus::assertDispatched(SendDiscordNotificationJob::class);
}
/**
* When a synonym is updated, a SendDiscordNotification job shall be dispatched.
*
* @return void
*/
public function testSynonymUpdatedSendsDiscordNotification(): void
{
$synonym = AnimeSynonym::factory()
->for(Anime::factory())
->createOne();
$changes = AnimeSynonym::factory()
->for(Anime::factory())
->makeOne();
Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS);
Bus::fake(SendDiscordNotificationJob::class);
Event::fakeExcept(SynonymUpdated::class);
$synonym->fill($changes->getAttributes());
$synonym->save();
Bus::assertDispatched(SendDiscordNotificationJob::class);
}
}