2024-02-24 15:37:01 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Feature;
|
|
|
|
|
|
|
|
use App\Models\Playlist;
|
|
|
|
use App\Services\MediaMetadataService;
|
|
|
|
use Mockery;
|
|
|
|
use Mockery\MockInterface;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
use function Tests\create_user;
|
|
|
|
|
|
|
|
class PlaylistCoverTest extends TestCase
|
|
|
|
{
|
|
|
|
private MockInterface|MediaMetadataService $mediaMetadataService;
|
|
|
|
|
|
|
|
public function setUp(): void
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->mediaMetadataService = self::mock(MediaMetadataService::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testUploadCover(): void
|
|
|
|
{
|
|
|
|
$playlist = Playlist::factory()->create();
|
|
|
|
self::assertNull($playlist->cover);
|
|
|
|
|
|
|
|
$this->mediaMetadataService
|
|
|
|
->shouldReceive('writePlaylistCover')
|
|
|
|
->once()
|
2024-03-22 20:34:32 +00:00
|
|
|
->with(Mockery::on(static fn (Playlist $target) => $target->is($playlist)), 'data:image/jpeg;base64,Rm9v');
|
2024-02-24 15:37:01 +00:00
|
|
|
|
2024-03-22 20:34:32 +00:00
|
|
|
$this->putAs("api/playlists/$playlist->id/cover", ['cover' => 'data:image/jpeg;base64,Rm9v'], $playlist->user)
|
2024-02-24 15:37:01 +00:00
|
|
|
->assertOk();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testUploadCoverNotAllowedForNonOwner(): void
|
|
|
|
{
|
|
|
|
$playlist = Playlist::factory()->create();
|
|
|
|
|
|
|
|
$this->mediaMetadataService->shouldNotReceive('writePlaylistCover');
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|