2020-04-26 19:09:43 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Feature;
|
|
|
|
|
|
|
|
use App\Events\LibraryChanged;
|
|
|
|
use App\Models\Artist;
|
|
|
|
use App\Models\User;
|
|
|
|
use App\Services\MediaMetadataService;
|
|
|
|
use Mockery;
|
|
|
|
use Mockery\MockInterface;
|
|
|
|
|
|
|
|
class ArtistImageTest extends TestCase
|
|
|
|
{
|
|
|
|
/** @var MockInterface|MediaMetadataService */
|
|
|
|
private $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);
|
2020-04-26 19:09:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testUpdate(): void
|
|
|
|
{
|
|
|
|
$this->expectsEvents(LibraryChanged::class);
|
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()
|
|
|
|
->with(Mockery::on(static function (Artist $artist): bool {
|
2020-09-06 21:20:42 +00:00
|
|
|
return $artist->id === 9999;
|
2020-04-26 19:09:43 +00:00
|
|
|
}), 'Foo', 'jpeg');
|
|
|
|
|
2022-07-27 08:49:33 +00:00
|
|
|
$this->putAs('api/artist/9999/image', [
|
2020-09-06 21:20:42 +00:00
|
|
|
'image' => 'data:image/jpeg;base64,Rm9v',
|
2020-11-14 16:57:25 +00:00
|
|
|
], User::factory()->admin()->create())
|
2020-09-06 18:21:39 +00:00
|
|
|
->assertStatus(200);
|
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
|
|
|
|
|
|
|
$this->mediaMetadataService
|
|
|
|
->shouldReceive('writeArtistImage')
|
|
|
|
->never();
|
|
|
|
|
2022-07-27 08:49:33 +00:00
|
|
|
$this->putAs('api/artist/9999/image', [
|
2020-09-06 21:20:42 +00:00
|
|
|
'image' => 'data:image/jpeg;base64,Rm9v',
|
2020-11-14 16:57:25 +00:00
|
|
|
], User::factory()->create())
|
2020-09-06 18:21:39 +00:00
|
|
|
->assertStatus(403);
|
2020-04-26 19:09:43 +00:00
|
|
|
}
|
|
|
|
}
|