Files
animethemes-server/tests/Feature/Jobs/Admin/FeatureTest.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

77 lines
2.1 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Feature\Jobs\Admin;
use App\Constants\FeatureConstants;
use App\Events\Admin\Feature\FeatureCreated;
use App\Events\Admin\Feature\FeatureDeleted;
use App\Events\Admin\Feature\FeatureUpdated;
use App\Jobs\SendDiscordNotificationJob;
use App\Models\Admin\Feature as FeatureModel;
use Illuminate\Support\Facades\Bus;
use Illuminate\Support\Facades\Event;
use Laravel\Pennant\Feature;
use Tests\TestCase;
/**
* Class FeatureTest.
*/
class FeatureTest extends TestCase
{
/**
* When a feature is created, a SendDiscordNotification job shall be dispatched.
*
* @return void
*/
public function testFeatureCreatedSendsDiscordNotification(): void
{
Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS);
Bus::fake(SendDiscordNotificationJob::class);
Event::fakeExcept(FeatureCreated::class);
FeatureModel::factory()->createOne();
Bus::assertDispatched(SendDiscordNotificationJob::class);
}
/**
* When a feature is deleted, a SendDiscordNotification job shall be dispatched.
*
* @return void
*/
public function testFeatureDeletedSendsDiscordNotification(): void
{
$feature = FeatureModel::factory()->createOne();
Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS);
Bus::fake(SendDiscordNotificationJob::class);
Event::fakeExcept(FeatureDeleted::class);
$feature->delete();
Bus::assertDispatched(SendDiscordNotificationJob::class);
}
/**
* When a feature is updated, a SendDiscordNotification job shall be dispatched.
*
* @return void
*/
public function testFeatureUpdatedSendsDiscordNotification(): void
{
$feature = FeatureModel::factory()->createOne();
Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS);
Bus::fake(SendDiscordNotificationJob::class);
Event::fakeExcept(FeatureUpdated::class);
$feature->update([
FeatureModel::ATTRIBUTE_VALUE => ! $feature->value,
]);
Bus::assertDispatched(SendDiscordNotificationJob::class);
}
}