diff --git a/module/Rest/test-api/Action/VisitStatsTest.php b/module/Rest/test-api/Action/VisitStatsTest.php new file mode 100644 index 00000000..424eba73 --- /dev/null +++ b/module/Rest/test-api/Action/VisitStatsTest.php @@ -0,0 +1,68 @@ +callApiWithKey(self::METHOD_GET, '/visits', apiKey: $apiKey); + $payload = $this->getJsonResponsePayload($resp); + + self::assertEquals(['visits' => $expectedPayload], $payload); + } + + public function provideApiKeysAndResults(): iterable + { + yield 'valid API key' => ['valid_api_key', [ + 'nonOrphanVisits' => [ + 'total' => 7, + 'nonBots' => 6, + 'bots' => 1, + ], + 'orphanVisits' => [ + 'total' => 3, + 'nonBots' => 2, + 'bots' => 1, + ], + 'visitsCount' => 7, + 'orphanVisitsCount' => 3, + ]]; + yield 'domain-only API key' => ['domain_api_key', [ + 'nonOrphanVisits' => [ + 'total' => 0, + 'nonBots' => 0, + 'bots' => 0, + ], + 'orphanVisits' => [ + 'total' => 3, + 'nonBots' => 2, + 'bots' => 1, + ], + 'visitsCount' => 0, + 'orphanVisitsCount' => 3, + ]]; + yield 'author API key' => ['author_api_key', [ + 'nonOrphanVisits' => [ + 'total' => 5, + 'nonBots' => 4, + 'bots' => 1, + ], + 'orphanVisits' => [ + 'total' => 3, + 'nonBots' => 2, + 'bots' => 1, + ], + 'visitsCount' => 5, + 'orphanVisitsCount' => 3, + ]]; + } +}