diff --git a/app/Dto/QueryTopReviewsCommand.php b/app/Dto/QueryTopReviewsCommand.php index b9ede8ef..322b66f1 100644 --- a/app/Dto/QueryTopReviewsCommand.php +++ b/app/Dto/QueryTopReviewsCommand.php @@ -2,14 +2,12 @@ namespace App\Dto; -use App\Casts\ContextualBooleanCast; use App\Casts\EnumCast; use App\Concerns\HasRequestFingerprint; use App\Contracts\DataRequest; use App\Dto\Concerns\HasPreliminaryParameter; use App\Dto\Concerns\HasSpoilersParameter; use App\Dto\Concerns\PreparesData; -use App\Enums\TopAnimeFilterEnum; use App\Enums\TopReviewsTypeEnum; use App\Rules\Attributes\EnumValidation; use Illuminate\Http\JsonResponse; @@ -23,6 +21,6 @@ final class QueryTopReviewsCommand extends QueryTopItemsCommand implements DataR { use HasRequestFingerprint, HasPreliminaryParameter, HasSpoilersParameter, PreparesData; - #[WithCast(EnumCast::class, TopAnimeFilterEnum::class), EnumValidation(TopReviewsTypeEnum::class)] + #[WithCast(EnumCast::class, TopReviewsTypeEnum::class), EnumValidation(TopReviewsTypeEnum::class)] public TopReviewsTypeEnum|Optional $type; } diff --git a/app/Features/QueryTopReviewsHandler.php b/app/Features/QueryTopReviewsHandler.php index 6eaae8b4..932cc0da 100644 --- a/app/Features/QueryTopReviewsHandler.php +++ b/app/Features/QueryTopReviewsHandler.php @@ -31,7 +31,7 @@ protected function getScraperData(string $requestFingerPrint, Collection $reques $preliminary = $requestParams->get("preliminary", true); return $this->scraperService->findList( $requestFingerPrint, - fn (MalClient $jikan, ?int $page = null) => $jikan->getReviews(new ReviewsRequest($type, $page, $spoilers, $preliminary)), + fn (MalClient $jikan, ?int $page = null) => $jikan->getReviews(new ReviewsRequest($type->value, $page, $spoilers, $preliminary)), $requestParams->get("page")); } } diff --git a/composer.lock b/composer.lock index b7d9f1aa..572b6df8 100644 --- a/composer.lock +++ b/composer.lock @@ -4554,16 +4554,16 @@ }, { "name": "jikan-me/jikan", - "version": "v4.0.11", + "version": "v4.0.12", "source": { "type": "git", "url": "https://github.com/jikan-me/jikan.git", - "reference": "fcc8d20817ce29332b496a21652b9965c6c8196c" + "reference": "dcb47237a9407473f484bd28a5e44479cdd916fc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/jikan-me/jikan/zipball/fcc8d20817ce29332b496a21652b9965c6c8196c", - "reference": "fcc8d20817ce29332b496a21652b9965c6c8196c", + "url": "https://api.github.com/repos/jikan-me/jikan/zipball/dcb47237a9407473f484bd28a5e44479cdd916fc", + "reference": "dcb47237a9407473f484bd28a5e44479cdd916fc", "shasum": "" }, "require": { @@ -4602,7 +4602,7 @@ "description": "Jikan is an unofficial MyAnimeList API", "support": { "issues": "https://github.com/jikan-me/jikan/issues", - "source": "https://github.com/jikan-me/jikan/tree/v4.0.11" + "source": "https://github.com/jikan-me/jikan/tree/v4.0.12" }, "funding": [ { @@ -4610,7 +4610,7 @@ "type": "patreon" } ], - "time": "2024-05-30T08:15:50+00:00" + "time": "2024-09-20T22:15:42+00:00" }, { "name": "jms/metadata", @@ -13591,5 +13591,5 @@ "ext-mongodb": "*" }, "platform-dev": [], - "plugin-api-version": "2.6.0" + "plugin-api-version": "2.3.0" } diff --git a/tests/Integration/TopControllerTest.php b/tests/Integration/TopControllerTest.php index e85ca9ff..22f0e462 100644 --- a/tests/Integration/TopControllerTest.php +++ b/tests/Integration/TopControllerTest.php @@ -7,6 +7,11 @@ use App\Testing\ScoutFlush; use App\Testing\SyntheticMongoDbTransaction; use Illuminate\Database\Eloquent\Factories\Sequence; +use Jikan\Exception\BadResponseException; +use Jikan\Exception\ParserException; +use Jikan\Model\Reviews\Reviews; +use Jikan\MyAnimeList\MalClient; +use Jikan\Parser\Reviews\ReviewsParser; use Tests\TestCase; class TopControllerTest extends TestCase @@ -14,6 +19,15 @@ class TopControllerTest extends TestCase use SyntheticMongoDbTransaction; use ScoutFlush; + public function topReviewTypeParametersProvider(): array + { + return [ + "empty query string" => [[]], + "query string = `?type=anime`" => [["type" => "anime"]], + "query string = `?type=manga`" => [["type" => "manga"]], + ]; + } + public function testTopAnime() { Anime::factory(3)->state(new Sequence( @@ -290,4 +304,27 @@ public function test404() $this->get('/v4/top/anime/999') ->seeStatusCode(404); } + + /** + * @dataProvider topReviewTypeParametersProvider + * @param $params + * @return void + * @throws BadResponseException + * @throws ParserException + */ + public function testTopReviews($params) + { + $jikanParser = \Mockery::mock(MalClient::class)->makePartial(); + + $reviewsParser = \Mockery::mock(ReviewsParser::class)->makePartial(); + $reviewsParser->allows()->getReviews()->andReturn([]); + $reviewsParser->allows()->hasNextPage()->andReturn(false); + $reviewsFacade = Reviews::fromParser($reviewsParser); + + /** @noinspection PhpParamsInspection */ + $jikanParser->allows()->getReviews(\Mockery::any())->andReturn($reviewsFacade); + $this->app->instance('JikanParser', $jikanParser); + $this->getJsonResponse($params,"/v4/top/reviews"); + $this->seeStatusCode(200); + } }