koel/tests/Feature/AlbumCoverTest.php

48 lines
1.3 KiB
PHP
Raw Normal View History

<?php
namespace Tests\Feature;
use App\Models\Album;
use App\Services\MediaMetadataService;
use Mockery;
2022-07-27 15:32:36 +00:00
use Mockery\MockInterface;
2024-01-09 18:34:40 +00:00
use Tests\TestCase;
2024-01-11 12:41:33 +00:00
use function Tests\create_admin;
use function Tests\create_user;
class AlbumCoverTest extends TestCase
{
2022-07-27 15:32:36 +00:00
private MediaMetadataService|MockInterface $mediaMetadataService;
public function setUp(): void
{
parent::setUp();
2020-12-22 20:11:22 +00:00
2020-12-22 23:01:49 +00:00
$this->mediaMetadataService = self::mock(MediaMetadataService::class);
}
public function testUpdate(): void
{
2022-12-04 13:56:25 +00:00
$album = Album::factory()->create();
$this->mediaMetadataService
->shouldReceive('writeAlbumCover')
->once()
->with(Mockery::on(static fn (Album $target) => $target->is($album)), 'data:image/jpeg;base64,Rm9v');
2020-09-06 18:21:39 +00:00
$this->putAs("api/album/$album->id/cover", ['cover' => 'data:image/jpeg;base64,Rm9v'], create_admin())
2022-07-27 15:32:36 +00:00
->assertOk();
}
public function testUpdateNotAllowedForNormalUsers(): void
{
$album = Album::factory()->create();
$this->mediaMetadataService->shouldNotReceive('writeAlbumCover');
2024-01-11 12:41:33 +00:00
$this->putAs('api/album/' . $album->id . '/cover', ['cover' => 'data:image/jpeg;base64,Rm9v'], create_user())
2022-07-27 15:32:36 +00:00
->assertForbidden();
}
}