koel/tests/Feature/V6/SongTest.php

64 lines
1.3 KiB
PHP
Raw Normal View History

2022-07-26 20:23:34 +00:00
<?php
namespace Tests\Feature\V6;
2022-07-27 10:01:17 +00:00
use App\Models\Song;
class SongTest extends TestCase
2022-07-26 20:23:34 +00:00
{
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',
];
2022-07-27 10:01:17 +00:00
private const JSON_COLLECTION_STRUCTURE = [
'data' => [
'*' => self::JSON_STRUCTURE,
],
'links' => [
'first',
'last',
'prev',
'next',
],
'meta' => [
'current_page',
'from',
'path',
'per_page',
'to',
],
];
public function testIndex(): void
{
Song::factory(10)->create();
$this->getAs('api/songs')->assertJsonStructure(self::JSON_COLLECTION_STRUCTURE);
$this->getAs('api/songs?sort=title&order=desc')->assertJsonStructure(self::JSON_COLLECTION_STRUCTURE);
}
public function testShow(): void
{
/** @var Song $song */
$song = Song::factory()->create();
$this->getAs('api/songs/' . $song->id)->assertJsonStructure(self::JSON_STRUCTURE);
}
2022-07-26 20:23:34 +00:00
}