2020-04-26 19:09:43 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Feature;
|
|
|
|
|
|
|
|
use App\Events\LibraryChanged;
|
|
|
|
use App\Models\Album;
|
|
|
|
use App\Models\User;
|
|
|
|
use App\Services\MediaMetadataService;
|
|
|
|
use Mockery;
|
|
|
|
use Mockery\MockInterface;
|
|
|
|
|
|
|
|
class AlbumCoverTest extends TestCase
|
|
|
|
{
|
|
|
|
/** @var MockInterface|MediaMetadataService */
|
|
|
|
private $mediaMetadataService;
|
|
|
|
|
|
|
|
public function setUp(): void
|
|
|
|
{
|
|
|
|
parent::setUp();
|
2020-04-27 18:55:12 +00:00
|
|
|
$this->mediaMetadataService = static::mockIocDependency(MediaMetadataService::class);
|
2020-04-26 19:09:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testUpdate(): void
|
|
|
|
{
|
|
|
|
$this->expectsEvents(LibraryChanged::class);
|
|
|
|
factory(Album::class)->create(['id' => 9999]);
|
|
|
|
|
|
|
|
$this->mediaMetadataService
|
|
|
|
->shouldReceive('writeAlbumCover')
|
|
|
|
->once()
|
|
|
|
->with(Mockery::on(static function (Album $album): bool {
|
|
|
|
return $album->id === 9999;
|
|
|
|
}), 'Foo', 'jpeg');
|
|
|
|
|
|
|
|
$this->putAsUser('api/album/9999/cover', [
|
|
|
|
'cover' => 'data:image/jpeg;base64,Rm9v'
|
2020-04-26 19:14:23 +00:00
|
|
|
], factory(User::class, 'admin')->create())
|
|
|
|
->seeStatusCode(200);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testUpdateNotAllowedForNormalUsers(): void
|
|
|
|
{
|
|
|
|
factory(Album::class)->create(['id' => 9999]);
|
|
|
|
|
|
|
|
$this->mediaMetadataService
|
|
|
|
->shouldReceive('writeAlbumCover')
|
|
|
|
->never();
|
|
|
|
|
|
|
|
$this->putAsUser('api/album/9999/cover', [
|
|
|
|
'cover' => 'data:image/jpeg;base64,Rm9v'
|
|
|
|
], factory(User::class)->create())
|
|
|
|
->seeStatusCode(403);
|
2020-04-26 19:09:43 +00:00
|
|
|
}
|
|
|
|
}
|