2022-08-10 14:56:01 +00:00
|
|
|
<?php
|
|
|
|
|
2023-06-05 21:46:41 +00:00
|
|
|
namespace Tests\Feature;
|
2022-08-10 14:56:01 +00:00
|
|
|
|
|
|
|
use App\Models\PlaylistFolder;
|
2024-01-09 18:34:40 +00:00
|
|
|
use Tests\TestCase;
|
2022-08-10 14:56:01 +00:00
|
|
|
|
2024-01-11 12:41:33 +00:00
|
|
|
use function Tests\create_user;
|
|
|
|
|
2022-08-10 14:56:01 +00:00
|
|
|
class PlaylistFolderTest extends TestCase
|
|
|
|
{
|
|
|
|
private const JSON_STRUCTURE = [
|
|
|
|
'type',
|
|
|
|
'id',
|
|
|
|
'name',
|
|
|
|
'user_id',
|
|
|
|
'created_at',
|
|
|
|
];
|
|
|
|
|
2023-08-16 12:56:31 +00:00
|
|
|
public function testListing(): void
|
|
|
|
{
|
2024-01-11 12:41:33 +00:00
|
|
|
$user = create_user();
|
2023-08-16 12:56:31 +00:00
|
|
|
PlaylistFolder::factory()->for($user)->count(3)->create();
|
|
|
|
|
|
|
|
$this->getAs('api/playlist-folders', $user)
|
|
|
|
->assertJsonStructure(['*' => self::JSON_STRUCTURE])
|
|
|
|
->assertJsonCount(3, '*');
|
|
|
|
}
|
|
|
|
|
2022-08-10 14:56:01 +00:00
|
|
|
public function testCreate(): void
|
|
|
|
{
|
2024-01-11 12:41:33 +00:00
|
|
|
$user = create_user();
|
2022-08-10 14:56:01 +00:00
|
|
|
|
|
|
|
$this->postAs('api/playlist-folders', ['name' => 'Classical'], $user)
|
|
|
|
->assertJsonStructure(self::JSON_STRUCTURE);
|
|
|
|
|
|
|
|
$this->assertDatabaseHas(PlaylistFolder::class, ['name' => 'Classical', 'user_id' => $user->id]);
|
|
|
|
}
|
|
|
|
|
2022-09-08 05:06:49 +00:00
|
|
|
public function testUpdate(): void
|
|
|
|
{
|
|
|
|
/** @var PlaylistFolder $folder */
|
|
|
|
$folder = PlaylistFolder::factory()->create(['name' => 'Metal']);
|
|
|
|
|
|
|
|
$this->patchAs('api/playlist-folders/' . $folder->id, ['name' => 'Classical'], $folder->user)
|
|
|
|
->assertJsonStructure(self::JSON_STRUCTURE);
|
|
|
|
|
|
|
|
self::assertSame('Classical', $folder->fresh()->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testUnauthorizedUpdate(): void
|
|
|
|
{
|
|
|
|
/** @var PlaylistFolder $folder */
|
|
|
|
$folder = PlaylistFolder::factory()->create(['name' => 'Metal']);
|
|
|
|
|
|
|
|
$this->patchAs('api/playlist-folders/' . $folder->id, ['name' => 'Classical'])
|
|
|
|
->assertForbidden();
|
|
|
|
|
|
|
|
self::assertSame('Metal', $folder->fresh()->name);
|
|
|
|
}
|
|
|
|
|
2022-08-10 14:56:01 +00:00
|
|
|
public function testDelete(): void
|
|
|
|
{
|
|
|
|
/** @var PlaylistFolder $folder */
|
|
|
|
$folder = PlaylistFolder::factory()->create();
|
|
|
|
|
|
|
|
$this->deleteAs('api/playlist-folders/' . $folder->id, ['name' => 'Classical'], $folder->user)
|
|
|
|
->assertNoContent();
|
|
|
|
|
|
|
|
self::assertModelMissing($folder);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testNonAuthorizedDelete(): void
|
|
|
|
{
|
|
|
|
/** @var PlaylistFolder $folder */
|
|
|
|
$folder = PlaylistFolder::factory()->create();
|
|
|
|
|
|
|
|
$this->deleteAs('api/playlist-folders/' . $folder->id, ['name' => 'Classical'])
|
|
|
|
->assertForbidden();
|
|
|
|
|
|
|
|
self::assertModelExists($folder);
|
|
|
|
}
|
|
|
|
}
|