koel/tests/Feature/GenreTest.php

56 lines
1.7 KiB
PHP
Raw Normal View History

2022-10-21 20:06:43 +00:00
<?php
2023-06-05 21:46:41 +00:00
namespace Tests\Feature;
2022-10-21 20:06:43 +00:00
use App\Http\Resources\GenreResource;
use App\Http\Resources\SongResource;
2022-10-21 20:06:43 +00:00
use App\Models\Song;
use App\Values\Genre;
2024-01-09 18:34:40 +00:00
use Tests\TestCase;
2022-10-21 20:06:43 +00:00
class GenreTest extends TestCase
{
public function testGetAllGenres(): void
{
Song::factory()->count(5)->create(['genre' => 'Rock']);
Song::factory()->count(2)->create(['genre' => 'Pop']);
Song::factory()->count(10)->create(['genre' => '']);
$this->getAs('api/genres')
->assertJsonStructure(['*' => GenreResource::JSON_STRUCTURE])
2022-10-21 20:06:43 +00:00
->assertJsonFragment(['name' => 'Rock', 'song_count' => 5])
->assertJsonFragment(['name' => 'Pop', 'song_count' => 2])
->assertJsonFragment(['name' => Genre::NO_GENRE, 'song_count' => 10]);
}
public function testGetOneGenre(): void
{
Song::factory()->count(5)->create(['genre' => 'Rock']);
$this->getAs('api/genres/Rock')
->assertJsonStructure(GenreResource::JSON_STRUCTURE)
2022-10-21 20:06:43 +00:00
->assertJsonFragment(['name' => 'Rock', 'song_count' => 5]);
}
2023-06-05 21:46:41 +00:00
2022-10-21 20:06:43 +00:00
public function testGetNonExistingGenreThrowsNotFound(): void
{
$this->getAs('api/genres/NonExistingGenre')->assertNotFound();
}
public function testPaginateSongsInGenre(): void
{
Song::factory()->count(5)->create(['genre' => 'Rock']);
$this->getAs('api/genres/Rock/songs')
->assertJsonStructure(SongResource::PAGINATION_JSON_STRUCTURE);
2022-10-21 20:06:43 +00:00
}
public function testGetRandomSongsInGenre(): void
{
Song::factory()->count(5)->create(['genre' => 'Rock']);
$this->getAs('api/genres/Rock/songs/random?limit=500')
->assertJsonStructure(['*' => SongResource::JSON_STRUCTURE]);
2022-10-21 20:06:43 +00:00
}
}