diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 9f84527..4b8fb54 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -83,7 +83,9 @@ class AppServiceProvider extends ServiceProvider public function register(): void { $this->app->singleton(JikanConfig::class, fn() => new JikanConfig(config("jikan"))); - $this->app->singleton(\App\Contracts\SearchAnalyticsService::class, \App\Services\DefaultSearchAnalyticsService::class); + $this->app->singleton(\App\Contracts\SearchAnalyticsService::class, + env("APP_ENV") !== "testing" ? \App\Services\DefaultSearchAnalyticsService::class : + \App\Services\DummySearchAnalyticsService::class); $this->app->alias(JikanConfig::class, "jikan-config"); // cache options class is used to share the request scope level cache settings $this->app->singleton(CacheOptions::class); diff --git a/app/Services/DummySearchAnalyticsService.php b/app/Services/DummySearchAnalyticsService.php new file mode 100644 index 0000000..1b53691 --- /dev/null +++ b/app/Services/DummySearchAnalyticsService.php @@ -0,0 +1,14 @@ + "test", "approved" => true, "background" => "test", - "premiered" => $this->faker->randomElement(["Winter", "Spring", "Fall", "Summer"]), + "premiered" => $this->faker->randomElement(["Winter", "Spring", "Fall", "Summer"]) . " " . $this->faker->year(), "broadcast" => [ "day" => "", "time" => "", diff --git a/database/factories/ProfileFactory.php b/database/factories/ProfileFactory.php index f1f4b6e..1001c20 100644 --- a/database/factories/ProfileFactory.php +++ b/database/factories/ProfileFactory.php @@ -21,6 +21,7 @@ final class ProfileFactory extends JikanModelFactory return [ "mal_id" => $mal_id, "username" => $username, + "internal_username" => $username, "url" => $url, "request_hash" => sprintf("request:%s:%s", "users", $this->getItemTestUrl("users", $username)), "images" => [ diff --git a/tests/Integration/MangaSearchEndpointTest.php b/tests/Integration/MangaSearchEndpointTest.php index 231c247..27152de 100644 --- a/tests/Integration/MangaSearchEndpointTest.php +++ b/tests/Integration/MangaSearchEndpointTest.php @@ -98,9 +98,9 @@ class MangaSearchEndpointTest extends TestCase public function genresParameterCombinationsProvider(): array { return [ - [["genres" => "1,2"]], - [["genres_exclude" => "4,5", "type" => "tv"]], - [["genres" => "1,2", "genres_exclude" => "3", "min_score" => 8, "type" => "tv", "status" => "complete", "page" => 1]], + "?genres=1,2" => [["genres" => "1,2"]], + "?genres_exclude=4,5&type=manga" => [["genres_exclude" => "4,5", "type" => "manga"]], + "?genres=1,2&genres_exclude=3&min_score=8&type=manga&status=complete" => [["genres" => "1,2", "genres_exclude" => "3", "min_score" => 8, "type" => "manga", "status" => "complete", "page" => 1]], ]; } diff --git a/tests/Integration/UserControllerTest.php b/tests/Integration/UserControllerTest.php index b361626..c34e19b 100644 --- a/tests/Integration/UserControllerTest.php +++ b/tests/Integration/UserControllerTest.php @@ -19,8 +19,10 @@ class UserControllerTest extends TestCase public function testUserProfile() { + $username = "nekomata1037"; Profile::factory()->createOne([ - "username" => "nekomata1037" + "username" => $username, + "internal_username" => $username ]); $this->get('/v4/users/nekomata1037') ->seeStatusCode(200) @@ -46,8 +48,10 @@ class UserControllerTest extends TestCase public function testUserStatistics() { + $username = "nekomata1037"; Profile::factory()->createOne([ - "username" => "nekomata1037" + "username" => $username, + "internal_username" => $username ]); $this->get('/v4/users/nekomata1037/statistics') ->seeStatusCode(200) @@ -83,8 +87,10 @@ class UserControllerTest extends TestCase public function testUserAbout() { + $username = "nekomata1037"; Profile::factory()->createOne([ - "username" => "nekomata1037" + "username" => $username, + "internal_username" => $username ]); $this->get('/v4/users/nekomata1037/about') ->seeStatusCode(200) @@ -95,8 +101,10 @@ class UserControllerTest extends TestCase public function testUserFavorites() { + $username = "nekomata1037"; Profile::factory()->createOne([ - "username" => "nekomata1037" + "username" => $username, + "internal_username" => $username ]); $this->get('/v4/users/nekomata1037/favorites') ->seeStatusCode(200)