mirror of
https://github.com/AnimeThemes/animethemes-server.git
synced 2026-10-30 19:23:57 +01:00
* refactor: migration from laravel-enum package to native php enums * style: fix StyleCI findings
85 lines
2.2 KiB
PHP
85 lines
2.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Http\Api\Pivot\Wiki\ArtistSong;
|
|
|
|
use App\Enums\Auth\CrudPermission;
|
|
use App\Models\Auth\User;
|
|
use App\Models\Wiki\Artist;
|
|
use App\Models\Wiki\Song;
|
|
use App\Pivots\Wiki\ArtistSong;
|
|
use Laravel\Sanctum\Sanctum;
|
|
use Tests\TestCase;
|
|
|
|
/**
|
|
* Class ArtistSongStoreTest.
|
|
*/
|
|
class ArtistSongStoreTest extends TestCase
|
|
{
|
|
/**
|
|
* The Artist Song Store Endpoint shall be protected by sanctum.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function testProtected(): void
|
|
{
|
|
$artist = Artist::factory()->createOne();
|
|
$song = Song::factory()->createOne();
|
|
|
|
$parameters = ArtistSong::factory()->raw();
|
|
|
|
$response = $this->post(route('api.artistsong.store', ['artist' => $artist, 'song' => $song] + $parameters));
|
|
|
|
$response->assertUnauthorized();
|
|
}
|
|
|
|
/**
|
|
* The Artist Song Store Endpoint shall forbid users without the create artist & create song permissions.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function testForbidden(): void
|
|
{
|
|
$artist = Artist::factory()->createOne();
|
|
$song = Song::factory()->createOne();
|
|
|
|
$parameters = ArtistSong::factory()->raw();
|
|
|
|
$user = User::factory()->createOne();
|
|
|
|
Sanctum::actingAs($user);
|
|
|
|
$response = $this->post(route('api.artistsong.store', ['artist' => $artist, 'song' => $song] + $parameters));
|
|
|
|
$response->assertForbidden();
|
|
}
|
|
|
|
/**
|
|
* The Artist Song Store Endpoint shall create an artist song.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function testCreate(): void
|
|
{
|
|
$artist = Artist::factory()->createOne();
|
|
$song = Song::factory()->createOne();
|
|
|
|
$parameters = ArtistSong::factory()->raw();
|
|
|
|
$user = User::factory()
|
|
->withPermissions(
|
|
CrudPermission::CREATE->format(Artist::class),
|
|
CrudPermission::CREATE->format(Song::class)
|
|
)
|
|
->createOne();
|
|
|
|
Sanctum::actingAs($user);
|
|
|
|
$response = $this->post(route('api.artistsong.store', ['artist' => $artist, 'song' => $song] + $parameters));
|
|
|
|
$response->assertCreated();
|
|
static::assertDatabaseCount(ArtistSong::class, 1);
|
|
}
|
|
}
|