Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fixed an issue with casting query string params on /top/reviews endpoint #549

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions app/Dto/QueryTopReviewsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
2 changes: 1 addition & 1 deletion app/Features/QueryTopReviewsHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
}
14 changes: 7 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions tests/Integration/TopControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,27 @@
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
{
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(
Expand Down Expand Up @@ -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);
}
}
Loading