feat: ajout d'une modale de gestion des chapitres, permettant la création, l'édition et le déplacement de chapitres. Mise à jour de l'API pour gérer les modifications en lot des chapitres, ainsi que l'intégration de tests pour valider cette nouvelle fonctionnalité. Amélioration de l'interface utilisateur pour une gestion plus fluide des chapitres.
This commit is contained in:
parent
00d63dffeb
commit
551db0bf77
126
tests/Feature/Manga/EditMultipleChaptersTest.php
Normal file
126
tests/Feature/Manga/EditMultipleChaptersTest.php
Normal file
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Manga;
|
||||
|
||||
use App\Entity\Chapter;
|
||||
use App\Entity\Manga;
|
||||
use Zenstruck\Foundry\Test\ResetDatabase;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
|
||||
class EditMultipleChaptersTest extends WebTestCase
|
||||
{
|
||||
use ResetDatabase;
|
||||
|
||||
public function test_it_edits_multiple_chapters(): void
|
||||
{
|
||||
// Given
|
||||
$client = static::createClient();
|
||||
|
||||
// Créer un manga et des chapitres de test
|
||||
$entityManager = static::getContainer()->get('doctrine')->getManager();
|
||||
|
||||
$manga = new Manga();
|
||||
$manga->setTitle('Test Manga');
|
||||
$manga->setSlug('test-manga');
|
||||
$manga->setMonitored(true);
|
||||
$entityManager->persist($manga);
|
||||
|
||||
$chapter1 = new Chapter();
|
||||
$chapter1->setManga($manga);
|
||||
$chapter1->setNumber(1.0);
|
||||
$chapter1->setTitle('Old Title 1');
|
||||
$chapter1->setVolume(1);
|
||||
$entityManager->persist($chapter1);
|
||||
|
||||
$chapter2 = new Chapter();
|
||||
$chapter2->setManga($manga);
|
||||
$chapter2->setNumber(2.0);
|
||||
$chapter2->setTitle('Old Title 2');
|
||||
$chapter2->setVolume(1);
|
||||
$entityManager->persist($chapter2);
|
||||
|
||||
$entityManager->flush();
|
||||
|
||||
$data = [
|
||||
'chapters' => [
|
||||
[
|
||||
'id' => (string) $chapter1->getId(),
|
||||
'title' => 'New Title 1',
|
||||
'volume' => 2
|
||||
],
|
||||
[
|
||||
'id' => (string) $chapter2->getId(),
|
||||
'title' => null,
|
||||
'volume' => 3
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
// When
|
||||
$client->request('POST', '/api/chapters/batch-edit', [], [], [
|
||||
'CONTENT_TYPE' => 'application/json'
|
||||
], json_encode($data));
|
||||
|
||||
// Then
|
||||
$this->assertResponseIsSuccessful();
|
||||
|
||||
// Vérifier que les chapitres ont été mis à jour
|
||||
$entityManager->clear();
|
||||
|
||||
$updatedChapter1 = $entityManager->find(Chapter::class, $chapter1->getId());
|
||||
$this->assertEquals('New Title 1', $updatedChapter1->getTitle());
|
||||
$this->assertEquals(2, $updatedChapter1->getVolume());
|
||||
|
||||
$updatedChapter2 = $entityManager->find(Chapter::class, $chapter2->getId());
|
||||
$this->assertEquals('Old Title 2', $updatedChapter2->getTitle()); // Non modifié
|
||||
$this->assertEquals(3, $updatedChapter2->getVolume());
|
||||
}
|
||||
|
||||
public function test_it_returns_404_when_chapter_not_found(): void
|
||||
{
|
||||
// Given
|
||||
$client = static::createClient();
|
||||
|
||||
$data = [
|
||||
'chapters' => [
|
||||
[
|
||||
'id' => '999',
|
||||
'title' => 'New Title',
|
||||
'volume' => 1
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
// When
|
||||
$client->request('POST', '/api/chapters/batch-edit', [], [], [
|
||||
'CONTENT_TYPE' => 'application/json'
|
||||
], json_encode($data));
|
||||
|
||||
// Then
|
||||
$this->assertResponseStatusCodeSame(404);
|
||||
}
|
||||
|
||||
public function test_it_validates_required_fields(): void
|
||||
{
|
||||
// Given
|
||||
$client = static::createClient();
|
||||
|
||||
$data = [
|
||||
'chapters' => [
|
||||
[
|
||||
'title' => 'New Title',
|
||||
'volume' => 1
|
||||
// id manquant
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
// When
|
||||
$client->request('POST', '/api/chapters/batch-edit', [], [], [
|
||||
'CONTENT_TYPE' => 'application/json'
|
||||
], json_encode($data));
|
||||
|
||||
// Then
|
||||
$this->assertResponseStatusCodeSame(500); // Erreur interne due à la validation manuelle
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user