From 56687ace50142361857df8efb593ec67642897e2 Mon Sep 17 00:00:00 2001 From: pushrbx Date: Thu, 25 Jan 2024 23:17:46 +0000 Subject: [PATCH] fixed tests across the board --- tests/Integration/AnimeSearchEndpointTest.php | 7 ++-- tests/Integration/MangaSearchEndpointTest.php | 7 ++-- tests/Integration/TopAnimeEndpointTest.php | 30 ++++++++--------- tests/Integration/UserControllerTest.php | 33 ++++++++++++------- 4 files changed, 42 insertions(+), 35 deletions(-) diff --git a/tests/Integration/AnimeSearchEndpointTest.php b/tests/Integration/AnimeSearchEndpointTest.php index d0f0c24..196e28e 100644 --- a/tests/Integration/AnimeSearchEndpointTest.php +++ b/tests/Integration/AnimeSearchEndpointTest.php @@ -215,14 +215,13 @@ class AnimeSearchEndpointTest extends TestCase /** * @dataProvider emptyDateRangeProvider */ - public function testSearchByEmptyDatesShouldRaiseValidationError($params) + public function testSearchByEmptyDatesShouldNotRaiseValidationError($params) { $this->generateFiveSpecificAndTenRandomElementsInDb($params); - $content = $this->getJsonResponse($params); + $this->getJsonResponse($params); - $this->seeStatusCode(400); - $this->assertEquals("ValidationException", data_get($content, "type")); + $this->seeStatusCode(200); } /** diff --git a/tests/Integration/MangaSearchEndpointTest.php b/tests/Integration/MangaSearchEndpointTest.php index 27152de..6ab0738 100644 --- a/tests/Integration/MangaSearchEndpointTest.php +++ b/tests/Integration/MangaSearchEndpointTest.php @@ -196,14 +196,13 @@ class MangaSearchEndpointTest extends TestCase /** * @dataProvider emptyDateRangeProvider */ - public function testSearchByEmptyDatesShouldRaiseValidationError($params) + public function testSearchByEmptyDatesShouldNotRaiseValidationError($params) { $this->generateFiveSpecificAndTenRandomElementsInDb($params); - $content = $this->getJsonResponse($params); + $this->getJsonResponse($params); - $this->seeStatusCode(400); - $this->assertEquals("ValidationException", data_get($content, "type")); + $this->seeStatusCode(200); } /** diff --git a/tests/Integration/TopAnimeEndpointTest.php b/tests/Integration/TopAnimeEndpointTest.php index 2e2a3ad..3cc063e 100644 --- a/tests/Integration/TopAnimeEndpointTest.php +++ b/tests/Integration/TopAnimeEndpointTest.php @@ -29,17 +29,17 @@ class TopAnimeEndpointTest extends TestCase public function orderByFieldAndParamsData() { return [ - ["rank", false, []], - ["rank", false, ["filter" => "airing"]], - ["rank", false, ["type" => "tv"]], - ["rank", false, ["type" => "movie"]], - ["rank", false, ["type" => "ova"]], - ["rank", false, ["type" => "ona"]], - ["rank", false, ["type" => "special"]], - ["rank", false, ["type" => "music"]], - ["rank", false, ["filter" => "upcoming"]], - ["members", true, ["filter" => "bypopularity"]], - ["favorites", true, ["filter" => "favorite"]] + "empty query string" => ["score", true, []], + "query string: ?filter=airing" => ["score", true, ["filter" => "airing"]], + "query string: ?type=tv" => ["score", true, ["type" => "tv"]], + "query string: ?type=movie" => ["score", true, ["type" => "movie"]], + "query string: ?type=ova" => ["score", true, ["type" => "ova"]], + "query string: ?type=ona" => ["score", true, ["type" => "ona"]], + "query string: ?type=special" => ["score", true, ["type" => "special"]], + "query string: ?type=music" => ["score", true, ["type" => "music"]], + "query string: ?filter=upcoming" => ["members", true, ["filter" => "upcoming"]], + "query string: ?filter=bypopularity" => ["members", true, ["filter" => "bypopularity"]], + "query string: ?filter=favorite" => ["favorites", true, ["filter" => "favorite"]] ]; } @@ -57,10 +57,10 @@ class TopAnimeEndpointTest extends TestCase /* * Test whether the API orders the items correctly. It has to return items in similar order as MAL would * their search results. - * No filters / query string parameters -> sorted by rank - * filter = airing -> sorted by rank - * type = tv/movie/ova/ona/special -> sorted by rank - * filter = upcoming -> sorted by "members" attribute + * No filters / query string parameters -> sorted by score + * filter = airing -> sorted by score + * type = tv/movie/ova/ona/special -> sorted by score + * filter = upcoming -> sorted by "popularity" attribute * filter = favorites -> sorted by "favorites" attribute * filter = bypopular -> sorted by "members" attribute */ diff --git a/tests/Integration/UserControllerTest.php b/tests/Integration/UserControllerTest.php index 80fcc0c..fdbf337 100644 --- a/tests/Integration/UserControllerTest.php +++ b/tests/Integration/UserControllerTest.php @@ -13,6 +13,9 @@ use Jikan\Model\User\LastUpdates; use Jikan\Model\User\Profile as JikanProfile; use Jikan\Model\User\Reviews\UserReviews; use Jikan\MyAnimeList\MalClient; +use Jikan\Parser\User\Profile\FavoritesParser; +use Jikan\Parser\User\Profile\LastUpdatesParser; +use Jikan\Parser\User\Profile\MangaStatsParser; use Jikan\Parser\User\Profile\UserProfileParser; use Jikan\Request\User\UserRecommendationsRequest; use Tests\TestCase; @@ -103,8 +106,8 @@ class UserControllerTest extends TestCase $userProfileParser->allows() ->getJoinDate() ->andReturn(\DateTimeImmutable::createFromFormat(\DateTimeImmutable::RFC3339, "2000-10-01T00:00:00+00:00")); - $animeStats = \Mockery::mock(AnimeStats::class)->makePartial(); - $animeStats->allows([ + $animeStatsParser = \Mockery::mock(\Jikan\Parser\User\Profile\AnimeStatsParser::class)->makePartial(); + $animeStatsParser->allows([ "getDaysWatched" => 0, "getMeanScore" => 0, "getWatching" => 0, @@ -116,11 +119,12 @@ class UserControllerTest extends TestCase "getRewatched" => 0, "getEpisodesWatched" => 0 ]); + $animeStats = AnimeStats::fromParser($animeStatsParser); $userProfileParser->allows() ->getAnimeStats() ->andReturn($animeStats); - $mangaStats = \Mockery::mock(MangaStats::class)->makePartial(); - $mangaStats->allows([ + $mangaStatsParser = \Mockery::mock(MangaStatsParser::class)->makePartial(); + $mangaStatsParser->allows([ "getDaysRead" => 0, "getMeanScore" => 0, "getReading" => 0, @@ -133,16 +137,18 @@ class UserControllerTest extends TestCase "getChaptersRead" => 0, "getVolumesRead" => 0 ]); + $mangaStats = MangaStats::fromParser($mangaStatsParser); $userProfileParser->allows() ->getMangaStats() ->andReturn($mangaStats); - $favorites = \Mockery::mock(\Jikan\Model\User\Favorites::class)->makePartial(); - $favorites->allows([ + $favoritesParser = \Mockery::mock(FavoritesParser::class)->makePartial(); + $favoritesParser->allows([ "getAnime" => [], "getManga" => [], "getCharacters" => [], "getPeople" => [] ]); + $favorites = \Jikan\Model\User\Favorites::fromParser($favoritesParser); $userProfileParser->allows() ->getFavorites() ->andReturn($favorites); @@ -155,22 +161,25 @@ class UserControllerTest extends TestCase $userProfileParser->allows() ->getAbout() ->andReturn(null); - $lastUpdates = \Mockery::mock(LastUpdates::class)->makePartial(); - $lastUpdates->allows() - ->getAnime() + $lastUpdatesParser = \Mockery::mock(LastUpdatesParser::class)->makePartial(); + $lastUpdatesParser->allows() + ->getLastAnimeUpdates() ->andReturn([]); - $lastUpdates->allows() - ->getManga() + $lastUpdatesParser->allows() + ->getLastMangaUpdates() ->andReturn([]); + + $lastUpdates = LastUpdates::fromParser($lastUpdatesParser); $userProfileParser->allows() ->getUserLastUpdates() ->andReturn($lastUpdates); + $resultData = JikanProfile::fromParser($userProfileParser); /** @noinspection PhpParamsInspection */ $jikanParser->allows() ->getUserProfile(\Mockery::any()) - ->andReturn(JikanProfile::fromParser($userProfileParser)); + ->andReturn($resultData); $this->app->instance('JikanParser', $jikanParser);