mirror of
https://github.com/jikan-me/jikan-rest.git
synced 2025-02-20 11:23:35 +08:00
added tests for rating parameter
This commit is contained in:
parent
2d2a1c97ed
commit
251fccb5f6
@ -49,13 +49,7 @@ class AnimeFactory extends JikanModelFactory
|
||||
"airing" => $status == "Currently Airing",
|
||||
"aired" => new CarbonDateRange($aired_from, $aired_to),
|
||||
"duration" => "",
|
||||
"rating" => $this->faker->randomElement([
|
||||
"R - 17+ (violence & profanity)",
|
||||
"PG - Children",
|
||||
"PG-13 - Teens 13 or older",
|
||||
"R+ - Mild Nudity",
|
||||
"Rx - Hentai"
|
||||
]),
|
||||
"rating" => $this->getRandomRating(),
|
||||
"score" => $this->faker->randomFloat(2, 1.00, 9.99),
|
||||
"scored_by" => $this->faker->randomDigitNotNull(),
|
||||
"rank" => $this->faker->randomDigitNotNull(),
|
||||
@ -133,6 +127,18 @@ class AnimeFactory extends JikanModelFactory
|
||||
return $this->state($this->serializeStateDefinition($overrides));
|
||||
}
|
||||
|
||||
private function getRandomRating(): string
|
||||
{
|
||||
return $this->faker->randomElement([
|
||||
"G - All Ages",
|
||||
"PG - Children",
|
||||
"PG-13 - Teens 13 or older",
|
||||
"R - 17+ (violence & profanity)",
|
||||
"R+ - Mild Nudity",
|
||||
"Rx - Hentai"
|
||||
]);
|
||||
}
|
||||
|
||||
private function isScoreValueValid($score): bool
|
||||
{
|
||||
return $score <= 9.99 && $score >= 0.0;
|
||||
@ -189,6 +195,19 @@ class AnimeFactory extends JikanModelFactory
|
||||
$overrides["status"] = $statuses[$rndKey];
|
||||
}
|
||||
|
||||
if ($additionalParams->has("rating")) {
|
||||
$ratings = [
|
||||
"g" => "G - All Ages",
|
||||
"pg" => "PG - Children",
|
||||
"pg13" => "PG-13 - Teens 13 or older",
|
||||
"r17" => "R - 17+ (violence & profanity)",
|
||||
"r" => "R+ - Mild Nudity",
|
||||
"rx" => "Rx - Hentai",
|
||||
];
|
||||
$rndKey = $this->faker->randomElement(array_diff(array_keys($ratings), [strtolower($additionalParams["rating"])]));
|
||||
$overrides["rating"] = $ratings[$rndKey];
|
||||
}
|
||||
|
||||
if (($additionalParams->has("genres") && $additionalParams->has("genres_exclude")) || (
|
||||
!$additionalParams->has("genres") && $additionalParams->has("genres_exclude")
|
||||
) ) {
|
||||
@ -314,6 +333,18 @@ class AnimeFactory extends JikanModelFactory
|
||||
};
|
||||
}
|
||||
|
||||
if ($additionalParams->has("rating")) {
|
||||
$overrides["rating"] = match (strtolower($additionalParams["rating"])) {
|
||||
"g" => "G - All Ages",
|
||||
"pg" => "PG - Children",
|
||||
"pg13" => "PG-13 - Teens 13 or older",
|
||||
"r17" => "R - 17+ (violence & profanity)",
|
||||
"r" => "R+ - Mild Nudity",
|
||||
"rx" => "Rx - Hentai",
|
||||
default => $this->getRandomRating()
|
||||
};
|
||||
}
|
||||
|
||||
if ($additionalParams->has("genres")) {
|
||||
$overrides["genres"] = [];
|
||||
$genreIds = explode(",", $additionalParams["genres"]);
|
||||
|
@ -111,7 +111,13 @@ class AnimeSearchEndpointTest extends TestCase
|
||||
[["status" => "Upcoming"]],
|
||||
[["max_score" => "8"]],
|
||||
[["min_score" => "6"]],
|
||||
[["max_score" => "7", "min_score" => "3"]]
|
||||
[["max_score" => "7", "min_score" => "3"]],
|
||||
[["rating" => "pg"]],
|
||||
[["rating" => "rx"]],
|
||||
[["rating" => "r"]],
|
||||
[["rating" => "pg13"]],
|
||||
[["rating" => "g"]],
|
||||
[["rating" => "r17"]],
|
||||
];
|
||||
}
|
||||
|
||||
@ -120,7 +126,17 @@ class AnimeSearchEndpointTest extends TestCase
|
||||
return [
|
||||
[["max_score" => "634638"], 15],
|
||||
[["min_score" => "673473"], 0],
|
||||
[["max_score" => "72344", "min_score" => "3532325"], 0]
|
||||
[["max_score" => "72344", "min_score" => "3532325"], 0],
|
||||
[["max_score" => 1, "min_score" => 5], 0],
|
||||
];
|
||||
}
|
||||
|
||||
public function invalidRatingParameterProvider(): array
|
||||
{
|
||||
return [
|
||||
[["rating" => "6263ssd"], 15],
|
||||
[["rating" => "rx1"], 15],
|
||||
[["rating" => "pg133"], 15]
|
||||
];
|
||||
}
|
||||
|
||||
@ -334,6 +350,20 @@ class AnimeSearchEndpointTest extends TestCase
|
||||
$this->assertCount(5, $content["data"]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider invalidRatingParameterProvider
|
||||
*/
|
||||
public function testSearchByInvalidRatingParameters($params, $expectedCount)
|
||||
{
|
||||
$this->generateFiveSpecificAndTenRandomElementsInDb($params);
|
||||
$content = $this->getJsonResponse($params);
|
||||
|
||||
$this->seeStatusCode(200);
|
||||
$this->assertPaginationData($expectedCount);
|
||||
$this->assertIsArray($content["data"]);
|
||||
$this->assertCount($expectedCount, $content["data"]);
|
||||
}
|
||||
|
||||
public function testTypeSenseSearchPagination()
|
||||
{
|
||||
// this should test https://github.com/jikan-me/jikan-rest/issues/298
|
||||
|
Loading…
x
Reference in New Issue
Block a user