2024-02-24 15:37:01 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Feature;
|
|
|
|
|
|
|
|
use App\Models\Playlist;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
use function Tests\create_user;
|
2024-07-26 14:33:14 +00:00
|
|
|
use function Tests\read_as_data_url;
|
|
|
|
use function Tests\test_path;
|
2024-02-24 15:37:01 +00:00
|
|
|
|
|
|
|
class PlaylistCoverTest extends TestCase
|
|
|
|
{
|
|
|
|
public function testUploadCover(): void
|
|
|
|
{
|
|
|
|
$playlist = Playlist::factory()->create();
|
|
|
|
self::assertNull($playlist->cover);
|
|
|
|
|
2024-07-26 14:33:14 +00:00
|
|
|
$this->putAs(
|
|
|
|
"api/playlists/$playlist->id/cover",
|
|
|
|
['cover' => read_as_data_url(test_path('blobs/cover.png'))],
|
|
|
|
$playlist->user
|
|
|
|
)
|
2024-02-24 15:37:01 +00:00
|
|
|
->assertOk();
|
2024-07-26 14:33:14 +00:00
|
|
|
|
|
|
|
self::assertNotNull($playlist->refresh()->cover);
|
2024-02-24 15:37:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testUploadCoverNotAllowedForNonOwner(): void
|
|
|
|
{
|
|
|
|
$playlist = Playlist::factory()->create();
|
|
|
|
|
2024-03-22 20:34:32 +00:00
|
|
|
$this->putAs("api/playlists/$playlist->id/cover", ['cover' => 'data:image/jpeg;base64,Rm9v'], create_user())
|
2024-02-24 15:37:01 +00:00
|
|
|
->assertForbidden();
|
|
|
|
}
|
2024-07-26 14:33:14 +00:00
|
|
|
|
|
|
|
public function testDeleteCover(): void
|
|
|
|
{
|
|
|
|
$playlist = Playlist::factory()->create(['cover' => 'cover.jpg']);
|
|
|
|
|
|
|
|
$this->deleteAs("api/playlists/$playlist->id/cover", [], $playlist->user)
|
|
|
|
->assertNoContent();
|
|
|
|
|
|
|
|
self::assertNull($playlist->refresh()->cover);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testNonOwnerCannotDeleteCover(): void
|
|
|
|
{
|
|
|
|
$playlist = Playlist::factory()->create(['cover' => 'cover.jpg']);
|
|
|
|
|
|
|
|
$this->deleteAs("api/playlists/$playlist->id/cover", [], create_user())
|
|
|
|
->assertForbidden();
|
|
|
|
|
|
|
|
self::assertSame('cover.jpg', $playlist->refresh()->getRawOriginal('cover'));
|
|
|
|
}
|
2024-02-24 15:37:01 +00:00
|
|
|
}
|