feat: ajout d'une route GetMangaByIdHandler.php et fix de la SearchBar.vue

This commit is contained in:
ext.jeremy.guillot@maxicoffee.domains
2025-03-25 22:44:26 +01:00
parent ed0a075a6c
commit d9e935f7de
26 changed files with 519 additions and 79 deletions

View File

@@ -14,7 +14,7 @@ class GetMangaTest extends AbstractApiTestCase
{
// When
$client = static::createClient();
$response = $client->request('GET', '/api/mangas/999');
$response = $client->request('GET', '/api/mangas/by-id/999');
// Then
$this->assertResponseStatusCodeSame(404);
@@ -42,7 +42,7 @@ class GetMangaTest extends AbstractApiTestCase
// When
$client = static::createClient();
$response = $client->request('GET', '/api/mangas/' . $manga->getId());
$response = $client->request('GET', '/api/mangas/by-id/' . $manga->getId());
// Then
$this->assertResponseIsSuccessful();

View File

@@ -0,0 +1,139 @@
<?php
namespace App\Tests\Feature\Manga;
use App\Entity\Manga;
use App\Tests\Feature\AbstractApiTestCase;
use Zenstruck\Foundry\Test\ResetDatabase;
class SearchMangaTest extends AbstractApiTestCase
{
use ResetDatabase;
public function testSearchMangaWithEmptyQuery(): void
{
// When
$client = static::createClient();
$response = $client->request('GET', '/api/mangas/search', [
'query' => [
'q' => ''
]
]);
// Then
$this->assertResponseStatusCodeSame(400);
$this->assertJsonContains([
'hydra:title' => 'An error occurred',
'hydra:description' => 'Le terme de recherche doit contenir au moins 3 caractères'
]);
}
public function testSearchMangaWithShortQuery(): void
{
// When
$client = static::createClient();
$response = $client->request('GET', '/api/mangas/search', [
'query' => [
'q' => 'on'
]
]);
// Then
$this->assertResponseStatusCodeSame(400);
$this->assertJsonContains([
'hydra:title' => 'An error occurred',
'hydra:description' => 'Le terme de recherche doit contenir au moins 3 caractères'
]);
}
public function testSearchMangaByTitle(): void
{
// Given
$this->createManga('One Piece', 'one-piece');
$this->createManga('Dragon Ball', 'dragon-ball');
$this->createManga('One Punch Man', 'one-punch-man');
// When
$client = static::createClient();
$response = $client->request('GET', '/api/mangas/search', [
'query' => [
'q' => 'one'
]
]);
// Then
$this->assertResponseIsSuccessful();
$data = $response->toArray();
$this->assertCount(2, $data['items']);
$titles = array_map(fn($item) => $item['title'], $data['items']);
$this->assertContains('One Piece', $titles);
$this->assertContains('One Punch Man', $titles);
}
public function testSearchMangaBySlug(): void
{
// Given
$this->createManga('One Piece', 'one-piece');
$this->createManga('Dragon Ball', 'dragon-ball');
// When
$client = static::createClient();
$response = $client->request('GET', '/api/mangas/search', [
'query' => [
'q' => 'dragon'
]
]);
// Then
$this->assertResponseIsSuccessful();
$data = $response->toArray();
$this->assertCount(1, $data['items']);
$this->assertEquals('Dragon Ball', $data['items'][0]['title']);
$this->assertEquals('dragon-ball', $data['items'][0]['slug']);
}
// public function testSearchMangaWithPagination(): void
// {
// // Given
// $this->createManga('One Piece', 'one-piece');
// $this->createManga('One Punch Man', 'one-punch-man');
// $this->createManga('One Outs', 'one-outs');
// // When
// $client = static::createClient();
// $response = $client->request('GET', '/api/mangas/search', [
// 'query' => [
// 'q' => 'one',
// 'page' => 2,
// 'limit' => 1
// ]
// ]);
// // Then
// $this->assertResponseIsSuccessful();
// $data = $response->toArray();
// $this->assertCount(1, $data['items']);
// $this->assertTrue($data['hasNextPage']);
// $this->assertTrue($data['hasPreviousPage']);
// }
private function createManga(string $title, string $slug): void
{
$manga = new Manga();
$manga->setTitle($title)
->setSlug($slug)
->setDescription('Description test')
->setAuthor('Author test')
->setPublicationYear(2020)
->setGenres(['action'])
->setStatus('ongoing')
->setRating(4.5)
->setMonitored(false);
$this->entityManager->persist($manga);
$this->entityManager->flush();
}
}