mirror of
https://github.com/koel/koel
synced 2024-11-10 06:34:14 +00:00
feat(test|api): add AlbumInformation tests
This commit is contained in:
parent
0641e5b393
commit
aac3ca3cab
2 changed files with 76 additions and 0 deletions
|
@ -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) : '',
|
||||
|
|
75
tests/Feature/V6/AlbumInformationTest.php
Normal file
75
tests/Feature/V6/AlbumInformationTest.php
Normal 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);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue