mirror of
https://github.com/AnimeThemes/animethemes-server.git
synced 2026-09-19 19:07:31 +02:00
* refactor: migration from laravel-enum package to native php enums * style: fix StyleCI findings
90 lines
2.6 KiB
PHP
90 lines
2.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Http\Api\Pivot\Wiki\ArtistResource;
|
|
|
|
use App\Enums\Auth\CrudPermission;
|
|
use App\Models\Auth\User;
|
|
use App\Models\Wiki\Artist;
|
|
use App\Models\Wiki\ExternalResource;
|
|
use App\Pivots\Wiki\ArtistResource;
|
|
use Laravel\Sanctum\Sanctum;
|
|
use Tests\TestCase;
|
|
|
|
/**
|
|
* Class ArtistResourceUpdateTest.
|
|
*/
|
|
class ArtistResourceUpdateTest extends TestCase
|
|
{
|
|
/**
|
|
* The Artist Resource Update Endpoint shall be protected by sanctum.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function testProtected(): void
|
|
{
|
|
$artistResource = ArtistResource::factory()
|
|
->for(Artist::factory())
|
|
->for(ExternalResource::factory(), ArtistResource::RELATION_RESOURCE)
|
|
->createOne();
|
|
|
|
$parameters = ArtistResource::factory()->raw();
|
|
|
|
$response = $this->put(route('api.artistresource.update', ['artist' => $artistResource->artist, 'resource' => $artistResource->resource] + $parameters));
|
|
|
|
$response->assertUnauthorized();
|
|
}
|
|
|
|
/**
|
|
* The Artist Resource Update Endpoint shall forbid users without the update artist & update resource permissions.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function testForbidden(): void
|
|
{
|
|
$artistResource = ArtistResource::factory()
|
|
->for(Artist::factory())
|
|
->for(ExternalResource::factory(), ArtistResource::RELATION_RESOURCE)
|
|
->createOne();
|
|
|
|
$parameters = ArtistResource::factory()->raw();
|
|
|
|
$user = User::factory()->createOne();
|
|
|
|
Sanctum::actingAs($user);
|
|
|
|
$response = $this->put(route('api.artistresource.update', ['artist' => $artistResource->artist, 'resource' => $artistResource->resource] + $parameters));
|
|
|
|
$response->assertForbidden();
|
|
}
|
|
|
|
/**
|
|
* The Artist Resource Update Endpoint shall update an artist resource.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function testUpdate(): void
|
|
{
|
|
$artistResource = ArtistResource::factory()
|
|
->for(Artist::factory())
|
|
->for(ExternalResource::factory(), ArtistResource::RELATION_RESOURCE)
|
|
->createOne();
|
|
|
|
$parameters = ArtistResource::factory()->raw();
|
|
|
|
$user = User::factory()
|
|
->withPermissions(
|
|
CrudPermission::UPDATE->format(Artist::class),
|
|
CrudPermission::UPDATE->format(ExternalResource::class)
|
|
)
|
|
->createOne();
|
|
|
|
Sanctum::actingAs($user);
|
|
|
|
$response = $this->put(route('api.artistresource.update', ['artist' => $artistResource->artist, 'resource' => $artistResource->resource] + $parameters));
|
|
|
|
$response->assertOk();
|
|
}
|
|
}
|