Files
animethemes-server/tests/Feature/Events/Pivot/Wiki/ArtistResourceTest.php
T
paranarimasu 2e930b17ff feat: initial migration to Laravel 10 (#572)
* feat: initial migration to Laravel 10

* style: fix StyleCI findings
2023-04-18 16:22:36 -05:00

109 lines
3.2 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Feature\Events\Pivot\Wiki;
use App\Events\Pivot\Wiki\ArtistResource\ArtistResourceCreated;
use App\Events\Pivot\Wiki\ArtistResource\ArtistResourceDeleted;
use App\Events\Pivot\Wiki\ArtistResource\ArtistResourceUpdated;
use App\Models\Wiki\Artist;
use App\Models\Wiki\ExternalResource;
use App\Pivots\Wiki\ArtistResource;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Event;
use Tests\TestCase;
/**
* Class ArtistResourceTest.
*/
class ArtistResourceTest extends TestCase
{
/**
* When an Artist is attached to a Resource or vice versa, an ArtistResourceCreated event shall be dispatched.
*
* @return void
*/
public function testArtistResourceCreatedEventDispatched(): void
{
$artist = Artist::factory()->createOne();
$resource = ExternalResource::factory()->createOne();
$artist->resources()->attach($resource);
Event::assertDispatched(ArtistResourceCreated::class);
}
/**
* When an Artist is detached from a Resource or vice versa, an ArtistResourceDeleted event shall be dispatched.
*
* @return void
*/
public function testArtistResourceDeletedEventDispatched(): void
{
$artist = Artist::factory()->createOne();
$resource = ExternalResource::factory()->createOne();
$artist->resources()->attach($resource);
$artist->resources()->detach($resource);
Event::assertDispatched(ArtistResourceDeleted::class);
}
/**
* When an Artist Resource pivot is updated, an ArtistResourceUpdated event shall be dispatched.
*
* @return void
*/
public function testArtistResourceUpdatedEventDispatched(): void
{
$artist = Artist::factory()->createOne();
$resource = ExternalResource::factory()->createOne();
$artistResource = ArtistResource::factory()
->for($artist, 'artist')
->for($resource, 'resource')
->createOne();
$changes = ArtistResource::factory()
->for($artist, 'artist')
->for($resource, 'resource')
->makeOne();
$artistResource->fill($changes->getAttributes());
$artistResource->save();
Event::assertDispatched(ArtistResourceUpdated::class);
}
/**
* The ArtistResourceUpdated event shall contain embed fields.
*
* @return void
*/
public function testArtistResourceUpdatedEventEmbedFields(): void
{
$artist = Artist::factory()->createOne();
$resource = ExternalResource::factory()->createOne();
$artistResource = ArtistResource::factory()
->for($artist, 'artist')
->for($resource, 'resource')
->createOne();
$changes = ArtistResource::factory()
->for($artist, 'artist')
->for($resource, 'resource')
->makeOne();
$artistResource->fill($changes->getAttributes());
$artistResource->save();
Event::assertDispatched(ArtistResourceUpdated::class, function (ArtistResourceUpdated $event) {
$message = $event->getDiscordMessage();
return ! empty(Arr::get($message->embed, 'fields'));
});
}
}