feat(test|api): add AlbumInformation tests

This commit is contained in:
Phan An 2022-07-26 22:54:40 +02:00
parent 0641e5b393
commit aac3ca3cab
No known key found for this signature in database
GPG key ID: A81E4477F0BB6FDC
2 changed files with 76 additions and 0 deletions

View file

@ -25,6 +25,7 @@ final class AlbumInformation implements Arrayable
{
return self::make(
url: $data->url,
cover: $data->cover,
wiki: [
'summary' => isset($data->wiki) ? self::formatLastFmText($data->wiki->summary) : '',
'full' => isset($data->wiki) ? self::formatLastFmText($data->wiki->content) : '',

View file

@ -0,0 +1,75 @@
<?php
namespace Tests\Feature\V6;
use App\Models\Album;
use App\Services\MediaInformationService;
use App\Values\AlbumInformation;
use Mockery;
class AlbumInformationTest extends TestCase
{
private const JSON_STRUCTURE = [
'url',
'cover',
'wiki' => [
'summary',
'full',
],
'tracks' => [
'*' => [
'title',
'length',
'url',
],
],
];
public function testGet(): void
{
config(['koel.lastfm.key' => 'foo']);
config(['koel.lastfm.secret' => 'geheim']);
/** @var Album $album */
$album = Album::factory()->create();
$lastfm = self::mock(MediaInformationService::class);
$lastfm->shouldReceive('getAlbumInformation')
->with(Mockery::on(static fn (Album $a) => $a->is($album)))
->andReturn(AlbumInformation::make(
url: 'https://lastfm.com/album/foo',
cover: 'https://lastfm.com/cover/foo',
wiki: [
'summary' => 'foo',
'full' => 'bar',
],
tracks: [
[
'title' => 'foo',
'length' => 123,
'url' => 'https://lastfm.com/track/foo',
],
[
'title' => 'bar',
'length' => 456,
'url' => 'https://lastfm.com/track/bar',
],
]
));
$this->getAsUser('api/albums/' . $album->id . '/information')
->assertJsonStructure(self::JSON_STRUCTURE);
}
public function testGetWithoutLastFmStillReturnsValidStructure(): void
{
config(['koel.lastfm.key' => null]);
config(['koel.lastfm.secret' => null]);
/** @var Album $album */
$album = Album::factory()->create();
$this->getAsUser('api/albums/' . $album->id . '/information')
->assertJsonStructure(self::JSON_STRUCTURE);
}
}