2022-07-26 20:54:40 +00:00
|
|
|
<?php
|
|
|
|
|
2023-06-05 21:46:41 +00:00
|
|
|
namespace Tests\Feature;
|
2022-07-26 20:54:40 +00:00
|
|
|
|
|
|
|
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',
|
|
|
|
],
|
|
|
|
]
|
|
|
|
));
|
|
|
|
|
2022-07-27 08:49:33 +00:00
|
|
|
$this->getAs('api/albums/' . $album->id . '/information')
|
2022-07-26 20:54:40 +00:00
|
|
|
->assertJsonStructure(self::JSON_STRUCTURE);
|
|
|
|
}
|
|
|
|
|
2022-07-26 20:57:27 +00:00
|
|
|
public function testGetWithoutLastfmStillReturnsValidStructure(): void
|
2022-07-26 20:54:40 +00:00
|
|
|
{
|
|
|
|
config(['koel.lastfm.key' => null]);
|
|
|
|
config(['koel.lastfm.secret' => null]);
|
|
|
|
|
|
|
|
/** @var Album $album */
|
|
|
|
$album = Album::factory()->create();
|
|
|
|
|
2022-07-27 08:49:33 +00:00
|
|
|
$this->getAs('api/albums/' . $album->id . '/information')
|
2022-07-26 20:54:40 +00:00
|
|
|
->assertJsonStructure(self::JSON_STRUCTURE);
|
|
|
|
}
|
|
|
|
}
|