From 8ecc241a4bedb0636cebe7d25d483f7d596dc15e Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Mon, 2 Jan 2023 12:45:08 +0100 Subject: [PATCH] Added API test for the visits stats endpoint --- .../Rest/test-api/Action/VisitStatsTest.php | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 module/Rest/test-api/Action/VisitStatsTest.php 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, + ]]; + } +}