Files
animethemes-server/tests/Feature/Jobs/Auth/UserTest.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\Auth;
use App\Constants\FeatureConstants;
use App\Events\Auth\User\UserCreated;
use App\Events\Auth\User\UserDeleted;
use App\Events\Auth\User\UserRestored;
use App\Events\Auth\User\UserUpdated;
use App\Jobs\SendDiscordNotificationJob;
use App\Models\Auth\User;
use Illuminate\Support\Facades\Bus;
use Illuminate\Support\Facades\Event;
use Laravel\Pennant\Feature;
use Tests\TestCase;
/**
* Class UserTest.
*/
class UserTest extends TestCase
{
/**
* When a user is created, a SendDiscordNotification job shall be dispatched.
*
* @return void
*/
public function testUserCreatedSendsDiscordNotification(): void
{
Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS);
Bus::fake(SendDiscordNotificationJob::class);
Event::fakeExcept(UserCreated::class);
User::factory()->createOne();
Bus::assertDispatched(SendDiscordNotificationJob::class);
}
/**
* When a user is deleted, a SendDiscordNotification job shall be dispatched.
*
* @return void
*/
public function testUserDeletedSendsDiscordNotification(): void
{
$user = User::factory()->createOne();
Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS);
Bus::fake(SendDiscordNotificationJob::class);
Event::fakeExcept(UserDeleted::class);
$user->delete();
Bus::assertDispatched(SendDiscordNotificationJob::class);
}
/**
* When a user is restored, a SendDiscordNotification job shall be dispatched.
*
* @return void
*/
public function testUserRestoredSendsDiscordNotification(): void
{
$user = User::factory()->createOne();
Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS);
Bus::fake(SendDiscordNotificationJob::class);
Event::fakeExcept(UserRestored::class);
$user->restore();
Bus::assertDispatched(SendDiscordNotificationJob::class);
}
/**
* When a user is updated, a SendDiscordNotification job shall be dispatched.
*
* @return void
*/
public function testUserUpdatedSendsDiscordNotification(): void
{
$user = User::factory()->createOne();
Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS);
Bus::fake(SendDiscordNotificationJob::class);
Event::fakeExcept(UserUpdated::class);
$changes = User::factory()->makeOne();
$user->fill($changes->getAttributes());
$user->save();
Bus::assertDispatched(SendDiscordNotificationJob::class);
}
}