feat(test|api): add ArtistSong tests

This commit is contained in:
Phan An 2022-07-26 22:23:34 +02:00
parent 2da3ddc23c
commit a7b8f91fdc
No known key found for this signature in database
GPG key ID: A81E4477F0BB6FDC
3 changed files with 49 additions and 25 deletions

View file

@ -7,30 +7,6 @@ use App\Models\Song;
class AlbumSongTest extends TestCase
{
private const JSON_STRUCTURE = [
'type',
'id',
'title',
'lyrics',
'album_id',
'album_name',
'artist_id',
'artist_name',
'album_artist_id',
'album_artist_name',
'album_cover',
'length',
'liked',
'play_count',
'track',
'disc',
'created_at',
];
private const JSON_COLLECTION_STRUCTURE = [
'*' => self::JSON_STRUCTURE,
];
public function testIndex(): void
{
/** @var Album $album */
@ -41,6 +17,6 @@ class AlbumSongTest extends TestCase
]);
$this->getAsUser('api/albums/' . $album->id . '/songs')
->assertJsonStructure(self::JSON_COLLECTION_STRUCTURE);
->assertJsonStructure(['*' => SongTest::JSON_STRUCTURE]);
}
}

View file

@ -0,0 +1,22 @@
<?php
namespace Tests\Feature\V6;
use App\Models\Artist;
use App\Models\Song;
class ArtistSongTest extends TestCase
{
public function testIndex(): void
{
/** @var Artist $artist */
$artist = Artist::factory()->create();
Song::factory(5)->create([
'artist_id' => $artist->id,
]);
$this->getAsUser('api/artists/' . $artist->id . '/songs')
->assertJsonStructure(['*' => SongTest::JSON_STRUCTURE]);
}
}

View file

@ -0,0 +1,26 @@
<?php
namespace Tests\Feature\V6;
class SongTest
{
public const JSON_STRUCTURE = [
'type',
'id',
'title',
'lyrics',
'album_id',
'album_name',
'artist_id',
'artist_name',
'album_artist_id',
'album_artist_name',
'album_cover',
'length',
'liked',
'play_count',
'track',
'disc',
'created_at',
];
}