Files
animethemes-server/tests/Feature/Jobs/Wiki/GroupTest.php
T

97 lines
2.6 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Feature\Jobs\Wiki;
use App\Constants\FeatureConstants;
use App\Events\Wiki\Group\GroupCreated;
use App\Events\Wiki\Group\GroupDeleted;
use App\Events\Wiki\Group\GroupRestored;
use App\Events\Wiki\Group\GroupUpdated;
use App\Jobs\SendDiscordNotificationJob;
use App\Models\Wiki\Group;
use Illuminate\Support\Facades\Bus;
use Illuminate\Support\Facades\Event;
use Laravel\Pennant\Feature;
use Tests\TestCase;
/**
* Class GroupTest.
*/
class GroupTest extends TestCase
{
/**
* When a group is created, a SendDiscordNotification job shall be dispatched.
*
* @return void
*/
public function testGroupCreatedSendsDiscordNotification(): void
{
Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS);
Bus::fake(SendDiscordNotificationJob::class);
Event::fakeExcept(GroupCreated::class);
Group::factory()->createOne();
Bus::assertDispatched(SendDiscordNotificationJob::class);
}
/**
* When a group is deleted, a SendDiscordNotification job shall be dispatched.
*
* @return void
*/
public function testGroupDeletedSendsDiscordNotification(): void
{
$group = Group::factory()->createOne();
Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS);
Bus::fake(SendDiscordNotificationJob::class);
Event::fakeExcept(GroupDeleted::class);
$group->delete();
Bus::assertDispatched(SendDiscordNotificationJob::class);
}
/**
* When a group is restored, a SendDiscordNotification job shall be dispatched.
*
* @return void
*/
public function testGroupRestoredSendsDiscordNotification(): void
{
$group = Group::factory()->createOne();
Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS);
Bus::fake(SendDiscordNotificationJob::class);
Event::fakeExcept(GroupRestored::class);
$group->restore();
Bus::assertDispatched(SendDiscordNotificationJob::class);
}
/**
* When a group is updated, a SendDiscordNotification job shall be dispatched.
*
* @return void
*/
public function testGroupUpdatedSendsDiscordNotification(): void
{
$group = Group::factory()->createOne();
Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS);
Bus::fake(SendDiscordNotificationJob::class);
Event::fakeExcept(GroupUpdated::class);
$changes = Group::factory()->makeOne();
$group->fill($changes->getAttributes());
$group->save();
Bus::assertDispatched(SendDiscordNotificationJob::class);
}
}