feat(manga): regrouper les chapitres d'un volume importé dans la liste API
Les chapitres partageant le même pagesDirectory non-null et le même volume non-null (import CBZ en bloc) sont fusionnés en un seul item isVolumeGroup=true côté Application, avec volumeChaptersRange et volumeChapterCount. Le frontend affiche "Vol. X — Chapitres Y-Z" à la place de N lignes identiques.
This commit is contained in:
parent
c268b2c312
commit
fb8f64ee59
@@ -5,7 +5,9 @@ namespace App\Tests\Domain\Manga\Application\QueryHandler;
|
||||
use App\Domain\Manga\Application\Query\GetMangaChapters;
|
||||
use App\Domain\Manga\Application\QueryHandler\GetMangaChaptersHandler;
|
||||
use App\Domain\Manga\Domain\Exception\MangaNotFoundException;
|
||||
use App\Domain\Manga\Domain\Model\Chapter;
|
||||
use App\Domain\Manga\Domain\Model\Manga;
|
||||
use App\Domain\Manga\Domain\Model\ValueObject\ChapterId;
|
||||
use App\Domain\Manga\Domain\Model\ValueObject\MangaId;
|
||||
use App\Domain\Manga\Domain\Model\ValueObject\MangaSlug;
|
||||
use App\Domain\Manga\Domain\Model\ValueObject\MangaTitle;
|
||||
@@ -67,6 +69,139 @@ class GetMangaChaptersHandlerTest extends TestCase
|
||||
$this->assertTrue($response->hasPreviousPage());
|
||||
}
|
||||
|
||||
public function testGroupsVolumeChaptersWithSharedPagesDirectory(): void
|
||||
{
|
||||
// Arrange
|
||||
$this->givenMangaExists('1');
|
||||
$sharedDir = '/manga/vol1/';
|
||||
foreach ([1, 2, 3] as $num) {
|
||||
$this->repository->addChapter('1', new Chapter(
|
||||
id: new ChapterId((string) $num),
|
||||
mangaId: new MangaId('1'),
|
||||
number: (float) $num,
|
||||
title: null,
|
||||
volume: 1,
|
||||
isVisible: true,
|
||||
pagesDirectory: $sharedDir,
|
||||
));
|
||||
}
|
||||
|
||||
// Act
|
||||
$response = $this->handler->handle(new GetMangaChapters('1'));
|
||||
|
||||
// Assert
|
||||
$this->assertCount(1, $response->chapters);
|
||||
$this->assertEquals(1, $response->total);
|
||||
$item = $response->chapters[0];
|
||||
$this->assertTrue($item->isVolumeGroup);
|
||||
$this->assertEquals('1-3', $item->volumeChaptersRange);
|
||||
$this->assertEquals(3, $item->volumeChapterCount);
|
||||
$this->assertEquals(1, $item->volume);
|
||||
$this->assertEquals(1.0, $item->number);
|
||||
}
|
||||
|
||||
public function testGroupsSingleVolumeChapter(): void
|
||||
{
|
||||
// Arrange
|
||||
$this->givenMangaExists('1');
|
||||
$this->repository->addChapter('1', new Chapter(
|
||||
id: new ChapterId('10'),
|
||||
mangaId: new MangaId('1'),
|
||||
number: 5.0,
|
||||
title: null,
|
||||
volume: 2,
|
||||
isVisible: true,
|
||||
pagesDirectory: '/manga/vol2/',
|
||||
));
|
||||
|
||||
// Act
|
||||
$response = $this->handler->handle(new GetMangaChapters('1'));
|
||||
|
||||
// Assert
|
||||
$this->assertCount(1, $response->chapters);
|
||||
$item = $response->chapters[0];
|
||||
$this->assertTrue($item->isVolumeGroup);
|
||||
$this->assertEquals('5', $item->volumeChaptersRange);
|
||||
$this->assertEquals(1, $item->volumeChapterCount);
|
||||
}
|
||||
|
||||
public function testDoesNotGroupChaptersWithDistinctPagesDirectory(): void
|
||||
{
|
||||
// Arrange — 3 chapitres scrapés avec pagesDirectory distinctes, pas de volume
|
||||
$this->givenMangaExists('1');
|
||||
foreach ([1, 2, 3] as $num) {
|
||||
$this->repository->addChapter('1', new Chapter(
|
||||
id: new ChapterId((string) $num),
|
||||
mangaId: new MangaId('1'),
|
||||
number: (float) $num,
|
||||
title: null,
|
||||
volume: null,
|
||||
isVisible: true,
|
||||
pagesDirectory: '/manga/ch' . $num . '/',
|
||||
));
|
||||
}
|
||||
|
||||
// Act
|
||||
$response = $this->handler->handle(new GetMangaChapters('1'));
|
||||
|
||||
// Assert — 3 items distincts, aucun groupe
|
||||
$this->assertCount(3, $response->chapters);
|
||||
$this->assertEquals(3, $response->total);
|
||||
foreach ($response->chapters as $item) {
|
||||
$this->assertFalse($item->isVolumeGroup);
|
||||
}
|
||||
}
|
||||
|
||||
public function testMixedNormalAndVolumeChapters(): void
|
||||
{
|
||||
// Arrange — 2 chapitres scrapés + 3 chapitres de volume importé
|
||||
$this->givenMangaExists('1');
|
||||
|
||||
// Chapitres scrapés (pagesDirectory individuel, pas de volume)
|
||||
foreach ([1, 2] as $num) {
|
||||
$this->repository->addChapter('1', new Chapter(
|
||||
id: new ChapterId((string) $num),
|
||||
mangaId: new MangaId('1'),
|
||||
number: (float) $num,
|
||||
title: null,
|
||||
volume: null,
|
||||
isVisible: true,
|
||||
pagesDirectory: '/manga/ch' . $num . '/',
|
||||
));
|
||||
}
|
||||
|
||||
// Volume importé — 3 chapitres avec même pagesDirectory
|
||||
$sharedDir = '/manga/vol1/';
|
||||
foreach ([3, 4, 5] as $num) {
|
||||
$this->repository->addChapter('1', new Chapter(
|
||||
id: new ChapterId((string) ($num + 10)),
|
||||
mangaId: new MangaId('1'),
|
||||
number: (float) $num,
|
||||
title: null,
|
||||
volume: 1,
|
||||
isVisible: true,
|
||||
pagesDirectory: $sharedDir,
|
||||
));
|
||||
}
|
||||
|
||||
// Act
|
||||
$response = $this->handler->handle(new GetMangaChapters('1', sortOrder: 'asc'));
|
||||
|
||||
// Assert — 2 chapitres normaux + 1 groupe = 3 items
|
||||
$this->assertCount(3, $response->chapters);
|
||||
$this->assertEquals(3, $response->total);
|
||||
|
||||
// Les 2 premiers sont des chapitres normaux
|
||||
$this->assertFalse($response->chapters[0]->isVolumeGroup);
|
||||
$this->assertFalse($response->chapters[1]->isVolumeGroup);
|
||||
|
||||
// Le 3e est un groupe de volume
|
||||
$volumeItem = $response->chapters[2];
|
||||
$this->assertTrue($volumeItem->isVolumeGroup);
|
||||
$this->assertEquals('3-5', $volumeItem->volumeChaptersRange);
|
||||
$this->assertEquals(3, $volumeItem->volumeChapterCount);
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->repository->clear();
|
||||
|
||||
Reference in New Issue
Block a user