2022-07-26 20:57:27 +00:00
|
|
|
<?php
|
|
|
|
|
2023-06-05 21:46:41 +00:00
|
|
|
namespace Tests\Feature;
|
2022-07-26 20:57:27 +00:00
|
|
|
|
|
|
|
use App\Models\Artist;
|
|
|
|
use App\Services\MediaInformationService;
|
|
|
|
use App\Values\ArtistInformation;
|
|
|
|
use Mockery;
|
2024-01-09 18:34:40 +00:00
|
|
|
use Tests\TestCase;
|
2022-07-26 20:57:27 +00:00
|
|
|
|
|
|
|
class ArtistInformationTest extends TestCase
|
|
|
|
{
|
|
|
|
public function testGet(): void
|
|
|
|
{
|
|
|
|
config(['koel.lastfm.key' => 'foo']);
|
|
|
|
config(['koel.lastfm.secret' => 'geheim']);
|
|
|
|
|
|
|
|
$artist = Artist::factory()->create();
|
|
|
|
|
|
|
|
$lastfm = self::mock(MediaInformationService::class);
|
|
|
|
$lastfm->shouldReceive('getArtistInformation')
|
|
|
|
->with(Mockery::on(static fn (Artist $a) => $a->is($artist)))
|
|
|
|
->andReturn(ArtistInformation::make(
|
|
|
|
url: 'https://lastfm.com/artist/foo',
|
|
|
|
image: 'https://lastfm.com/image/foo',
|
|
|
|
bio: [
|
|
|
|
'summary' => 'foo',
|
|
|
|
'full' => 'bar',
|
|
|
|
],
|
|
|
|
));
|
|
|
|
|
2022-07-27 08:49:33 +00:00
|
|
|
$this->getAs('api/artists/' . $artist->id . '/information')
|
2024-01-25 16:21:26 +00:00
|
|
|
->assertJsonStructure(ArtistInformation::JSON_STRUCTURE);
|
2022-07-26 20:57:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetWithoutLastfmStillReturnsValidStructure(): void
|
|
|
|
{
|
|
|
|
config(['koel.lastfm.key' => null]);
|
|
|
|
config(['koel.lastfm.secret' => null]);
|
|
|
|
|
2024-04-24 21:58:19 +00:00
|
|
|
$this->getAs('api/artists/' . Artist::factory()->create()->id . '/information')
|
2024-01-25 16:21:26 +00:00
|
|
|
->assertJsonStructure(ArtistInformation::JSON_STRUCTURE);
|
2022-07-26 20:57:27 +00:00
|
|
|
}
|
|
|
|
}
|