mirror of
https://github.com/AnimeThemes/animethemes-server.git
synced 2026-07-28 17:54:42 +02:00
* 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
97 lines
2.9 KiB
PHP
97 lines
2.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Feature\Jobs\Wiki;
|
|
|
|
use App\Constants\FeatureConstants;
|
|
use App\Events\Wiki\ExternalResource\ExternalResourceCreated;
|
|
use App\Events\Wiki\ExternalResource\ExternalResourceDeleted;
|
|
use App\Events\Wiki\ExternalResource\ExternalResourceRestored;
|
|
use App\Events\Wiki\ExternalResource\ExternalResourceUpdated;
|
|
use App\Jobs\SendDiscordNotificationJob;
|
|
use App\Models\Wiki\ExternalResource;
|
|
use Illuminate\Support\Facades\Bus;
|
|
use Illuminate\Support\Facades\Event;
|
|
use Laravel\Pennant\Feature;
|
|
use Tests\TestCase;
|
|
|
|
/**
|
|
* Class ExternalResourceTest.
|
|
*/
|
|
class ExternalResourceTest extends TestCase
|
|
{
|
|
/**
|
|
* When a resource is created, a SendDiscordNotification job shall be dispatched.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function testResourceCreatedSendsDiscordNotification(): void
|
|
{
|
|
Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS);
|
|
Bus::fake(SendDiscordNotificationJob::class);
|
|
Event::fakeExcept(ExternalResourceCreated::class);
|
|
|
|
ExternalResource::factory()->createOne();
|
|
|
|
Bus::assertDispatched(SendDiscordNotificationJob::class);
|
|
}
|
|
|
|
/**
|
|
* When a resource is deleted, a SendDiscordNotification job shall be dispatched.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function testResourceDeletedSendsDiscordNotification(): void
|
|
{
|
|
$resource = ExternalResource::factory()->createOne();
|
|
|
|
Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS);
|
|
Bus::fake(SendDiscordNotificationJob::class);
|
|
Event::fakeExcept(ExternalResourceDeleted::class);
|
|
|
|
$resource->delete();
|
|
|
|
Bus::assertDispatched(SendDiscordNotificationJob::class);
|
|
}
|
|
|
|
/**
|
|
* When a resource is restored, a SendDiscordNotification job shall be dispatched.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function testResourceRestoredSendsDiscordNotification(): void
|
|
{
|
|
$resource = ExternalResource::factory()->createOne();
|
|
|
|
Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS);
|
|
Bus::fake(SendDiscordNotificationJob::class);
|
|
Event::fakeExcept(ExternalResourceRestored::class);
|
|
|
|
$resource->restore();
|
|
|
|
Bus::assertDispatched(SendDiscordNotificationJob::class);
|
|
}
|
|
|
|
/**
|
|
* When a resource is updated, a SendDiscordNotification job shall be dispatched.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function testResourceUpdatedSendsDiscordNotification(): void
|
|
{
|
|
$resource = ExternalResource::factory()->createOne();
|
|
|
|
Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS);
|
|
Bus::fake(SendDiscordNotificationJob::class);
|
|
Event::fakeExcept(ExternalResourceUpdated::class);
|
|
|
|
$changes = ExternalResource::factory()->makeOne();
|
|
|
|
$resource->fill($changes->getAttributes());
|
|
$resource->save();
|
|
|
|
Bus::assertDispatched(SendDiscordNotificationJob::class);
|
|
}
|
|
}
|