From 125b6720ff64bc71f2a36da588c7bf425525edf8 Mon Sep 17 00:00:00 2001 From: pushrbx Date: Tue, 30 Jan 2024 17:28:03 +0000 Subject: [PATCH 1/2] added more tests and improved existing ones --- database/factories/AnimeFactory.php | 2 +- tests/Integration/AnimeSearchEndpointTest.php | 36 ++++++------- tests/Integration/SeasonControllerTest.php | 52 +++++++++++++++++++ tests/Unit/PreparesDataTraitTest.php | 45 ++++++++++++++++ 4 files changed, 116 insertions(+), 19 deletions(-) create mode 100644 tests/Integration/SeasonControllerTest.php create mode 100644 tests/Unit/PreparesDataTraitTest.php diff --git a/database/factories/AnimeFactory.php b/database/factories/AnimeFactory.php index c226f73..786088f 100644 --- a/database/factories/AnimeFactory.php +++ b/database/factories/AnimeFactory.php @@ -23,7 +23,7 @@ class AnimeFactory extends JikanMediaModelFactory { $mal_id = $this->createMalId(); $title = $this->createTitle(); - $status = $this->faker->randomElement(["Currently Airing", "Completed", "Upcoming"]); + $status = $this->faker->randomElement(["Currently Airing", "Finished Airing", "Not yet aired"]); [$aired_from, $aired_to] = $this->createActiveDateRange($status, "Currently Airing"); return [ diff --git a/tests/Integration/AnimeSearchEndpointTest.php b/tests/Integration/AnimeSearchEndpointTest.php index 196e28e..7100478 100644 --- a/tests/Integration/AnimeSearchEndpointTest.php +++ b/tests/Integration/AnimeSearchEndpointTest.php @@ -120,24 +120,24 @@ class AnimeSearchEndpointTest extends TestCase public function commonParameterProvider(): array { return [ - [["status" => "airing"]], - [["status" => "complete"]], - [["status" => "upcoming"]], - [["status" => "Airing"]], - [["status" => "Complete"]], - [["status" => "Upcoming"]], - [["max_score" => "8"]], - [["min_score" => "6"]], - [["max_score" => "7", "min_score" => "3"]], - [["rating" => "pg"]], - [["rating" => "rx"]], - [["rating" => "r"]], - [["rating" => "pg13"]], - [["rating" => "g"]], - [["rating" => "r17"]], - [["type" => "movie"]], - [["type" => "ova"]], - [["type" => "special"]], + "status = airing" => [["status" => "airing"]], + "status = complete" => [["status" => "complete"]], + "status = upcoming" => [["status" => "upcoming"]], + "status = Airing" => [["status" => "Airing"]], + "status = Complete" => [["status" => "Complete"]], + "status = Upcoming" => [["status" => "Upcoming"]], + "max_score = 8" => [["max_score" => "8"]], + "min_score = 6" => [["min_score" => "6"]], + "max_score = 7, min_score = 3" => [["max_score" => "7", "min_score" => "3"]], + "rating = pg" => [["rating" => "pg"]], + "rating = rx" => [["rating" => "rx"]], + "rating = r" => [["rating" => "r"]], + "rating = pg13" => [["rating" => "pg13"]], + "rating = g" => [["rating" => "g"]], + "rating = r17" => [["rating" => "r17"]], + "type = movie" => [["type" => "movie"]], + "type = ova" => [["type" => "ova"]], + "type = special" => [["type" => "special"]], ]; } diff --git a/tests/Integration/SeasonControllerTest.php b/tests/Integration/SeasonControllerTest.php new file mode 100644 index 0000000..2879209 --- /dev/null +++ b/tests/Integration/SeasonControllerTest.php @@ -0,0 +1,52 @@ +serializeStateDefinition([ + "aired" => new CarbonDateRange($carbonStartDate, null) + ]); + $state["aired"]["string"] = "Jan 1, 2024 to ?"; + $state["premiered"] = null; + $state["status"] = "Not yet aired"; + $state["airing"] = false; + $f->create($state); + + // the correct item + $f = Anime::factory(1); + $state = $f->serializeStateDefinition([ + "aired" => new CarbonDateRange(Carbon::parse("2024-01-10"), Carbon::parse("2024-02-15")) + ]); + $state["premiered"] = "Winter 2024"; + $state["status"] = "Currently Airing"; + $state["airing"] = true; + $f->create($state); + + $content = $this->getJsonResponse([], "/v4/seasons/2024/winter"); + + Carbon::setTestNow(); + + $this->seeStatusCode(200); + $this->assertIsArray($content["data"]); + $this->assertCount(1, $content["data"]); + } +} diff --git a/tests/Unit/PreparesDataTraitTest.php b/tests/Unit/PreparesDataTraitTest.php new file mode 100644 index 0000000..64e0e53 --- /dev/null +++ b/tests/Unit/PreparesDataTraitTest.php @@ -0,0 +1,45 @@ + [['limit' => '', 'page' => '', 'filter' => ''], []], + 'limit = 1, page = empty, filter = empty' => [['limit' => '1', 'page' => '', 'filter' => ''], ['limit' => 1]], + 'limit = 1, page = 2, filter = empty' => [ + ['limit' => '1', 'page' => '2', 'filter' => ''], + ['limit' => 1, 'page' => 2] + ], + 'limit = 1, page = 2, filter = somefilter' => [ + ['limit' => '1', 'page' => '2', 'filter' => 'somefilter'], + ['limit' => 1, 'page' => 2, 'filter' => 'somefilter'] + ], + ]; + } + + /** + * @dataProvider paramsDataProvider + */ + public function testShouldIgnoreEmptyParams($actual, $expected) + { + $sut = PreparesDataFixture::prepareForPipeline(collect($actual)); + + $this->assertCollectionsStrictlyEqual(collect($expected), $sut); + } +} From 99fa9f92ee2efb5ab72d2d461cb818ec86fa250a Mon Sep 17 00:00:00 2001 From: pushrbx Date: Tue, 30 Jan 2024 17:46:05 +0000 Subject: [PATCH 2/2] fixed the "premiered" attribute on AnimeFactory class --- database/factories/AnimeFactory.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/database/factories/AnimeFactory.php b/database/factories/AnimeFactory.php index 786088f..202d753 100644 --- a/database/factories/AnimeFactory.php +++ b/database/factories/AnimeFactory.php @@ -26,6 +26,11 @@ class AnimeFactory extends JikanMediaModelFactory $status = $this->faker->randomElement(["Currently Airing", "Finished Airing", "Not yet aired"]); [$aired_from, $aired_to] = $this->createActiveDateRange($status, "Currently Airing"); + $premiered = $this->faker->randomElement(["Winter", "Spring", "Fall", "Summer"]) . " " . $this->faker->year(); + if ($status === "Not yet aired") { + $premiered = null; + } + return [ "mal_id" => $mal_id, "url" => $this->createMalUrl($mal_id, "anime"), @@ -68,7 +73,7 @@ class AnimeFactory extends JikanMediaModelFactory "synopsis" => "test", "approved" => true, "background" => "test", - "premiered" => $this->faker->randomElement(["Winter", "Spring", "Fall", "Summer"]) . " " . $this->faker->year(), + "premiered" => $premiered, "broadcast" => [ "day" => "", "time" => "",