koel/tests/Feature/ArtistImageTest.php

53 lines
1.4 KiB
PHP
Raw Normal View History

<?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
{
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
{
$this->expectsEvents(LibraryChanged::class);
2022-07-27 15:32:36 +00:00
/** @var User $admin */
$admin = User::factory()->admin()->create();
Artist::factory()->create(['id' => 9999]);
$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');
$this->putAs('api/artist/9999/image', ['image' => 'data:image/jpeg;base64,Rm9v'], $admin)
->assertOk();
}
public function testUpdateNotAllowedForNormalUsers(): void
{
Artist::factory()->create(['id' => 9999]);
$this->mediaMetadataService
->shouldReceive('writeArtistImage')
->never();
2022-07-27 15:32:36 +00:00
$this->putAs('api/artist/9999/image', ['image' => 'data:image/jpeg;base64,Rm9v'])
->assertForbidden();
}
}