Files
animethemes-server/tests/Feature/Jobs/Admin/DumpTest.php
T
paranarimasuandGitHub 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

97 lines
2.6 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Feature\Jobs\Admin;
use App\Constants\FeatureConstants;
use App\Events\Admin\Dump\DumpCreated;
use App\Events\Admin\Dump\DumpDeleted;
use App\Events\Admin\Dump\DumpRestored;
use App\Events\Admin\Dump\DumpUpdated;
use App\Jobs\SendDiscordNotificationJob;
use App\Models\Admin\Dump;
use Illuminate\Support\Facades\Bus;
use Illuminate\Support\Facades\Event;
use Laravel\Pennant\Feature;
use Tests\TestCase;
/**
* Class DumpTest.
*/
class DumpTest extends TestCase
{
/**
* When a dump is created, a SendDiscordNotification job shall be dispatched.
*
* @return void
*/
public function testDumpCreatedSendsDiscordNotification(): void
{
Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS);
Bus::fake(SendDiscordNotificationJob::class);
Event::fakeExcept(DumpCreated::class);
Dump::factory()->createOne();
Bus::assertDispatched(SendDiscordNotificationJob::class);
}
/**
* When a dump is deleted, a SendDiscordNotification job shall be dispatched.
*
* @return void
*/
public function testDumpDeletedSendsDiscordNotification(): void
{
$dump = Dump::factory()->createOne();
Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS);
Bus::fake(SendDiscordNotificationJob::class);
Event::fakeExcept(DumpDeleted::class);
$dump->delete();
Bus::assertDispatched(SendDiscordNotificationJob::class);
}
/**
* When a dump is restored, a SendDiscordNotification job shall be dispatched.
*
* @return void
*/
public function testDumpRestoredSendsDiscordNotification(): void
{
$dump = Dump::factory()->createOne();
Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS);
Bus::fake(SendDiscordNotificationJob::class);
Event::fakeExcept(DumpRestored::class);
$dump->restore();
Bus::assertDispatched(SendDiscordNotificationJob::class);
}
/**
* When a dump is updated, a SendDiscordNotification job shall be dispatched.
*
* @return void
*/
public function testDumpUpdatedSendsDiscordNotification(): void
{
$dump = Dump::factory()->createOne();
Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS);
Bus::fake(SendDiscordNotificationJob::class);
Event::fakeExcept(DumpUpdated::class);
$changes = Dump::factory()->makeOne();
$dump->fill($changes->getAttributes());
$dump->save();
Bus::assertDispatched(SendDiscordNotificationJob::class);
}
}