2020-04-26 19:09:43 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Feature;
|
|
|
|
|
|
|
|
use App\Models\Artist;
|
|
|
|
use App\Services\MediaMetadataService;
|
|
|
|
use Mockery;
|
|
|
|
use Mockery\MockInterface;
|
2024-01-09 18:34:40 +00:00
|
|
|
use Tests\TestCase;
|
2020-04-26 19:09:43 +00:00
|
|
|
|
2024-01-11 12:41:33 +00:00
|
|
|
use function Tests\create_admin;
|
|
|
|
|
2020-04-26 19:09:43 +00:00
|
|
|
class ArtistImageTest extends TestCase
|
|
|
|
{
|
2022-07-27 15:32:36 +00:00
|
|
|
private MediaMetadataService|MockInterface $mediaMetadataService;
|
2020-04-26 19:09:43 +00:00
|
|
|
|
|
|
|
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);
|
2020-04-26 19:09:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testUpdate(): void
|
|
|
|
{
|
2020-11-14 16:57:25 +00:00
|
|
|
Artist::factory()->create(['id' => 9999]);
|
2020-04-26 19:09:43 +00:00
|
|
|
|
|
|
|
$this->mediaMetadataService
|
|
|
|
->shouldReceive('writeArtistImage')
|
|
|
|
->once()
|
2022-07-27 15:32:36 +00:00
|
|
|
->with(Mockery::on(static fn (Artist $artist) => $artist->id === 9999), 'Foo', 'jpeg');
|
|
|
|
|
2024-01-11 12:41:33 +00:00
|
|
|
$this->putAs('api/artist/9999/image', ['image' => 'data:image/jpeg;base64,Rm9v'], create_admin())
|
2022-07-27 15:32:36 +00:00
|
|
|
->assertOk();
|
2020-04-26 19:14:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testUpdateNotAllowedForNormalUsers(): void
|
|
|
|
{
|
2020-11-14 16:57:25 +00:00
|
|
|
Artist::factory()->create(['id' => 9999]);
|
2020-04-26 19:14:23 +00:00
|
|
|
|
2024-01-11 16:52:55 +00:00
|
|
|
$this->mediaMetadataService->shouldNotReceive('writeArtistImage');
|
2020-04-26 19:14:23 +00:00
|
|
|
|
2022-07-27 15:32:36 +00:00
|
|
|
$this->putAs('api/artist/9999/image', ['image' => 'data:image/jpeg;base64,Rm9v'])
|
|
|
|
->assertForbidden();
|
2020-04-26 19:09:43 +00:00
|
|
|
}
|
|
|
|
}
|