diff --git a/module/Rest/test/Action/Visit/DomainVisitsActionTest.php b/module/Rest/test/Action/Visit/DomainVisitsActionTest.php new file mode 100644 index 00000000..84acb1f1 --- /dev/null +++ b/module/Rest/test/Action/Visit/DomainVisitsActionTest.php @@ -0,0 +1,60 @@ +visitsHelper = $this->prophesize(VisitsStatsHelperInterface::class); + $this->action = new DomainVisitsAction($this->visitsHelper->reveal(), 'the_default.com'); + } + + /** + * @test + * @dataProvider provideDomainAuthorities + */ + public function providingCorrectDomainReturnsVisits(string $providedDomain, string $expectedDomain): void + { + $apiKey = ApiKey::create(); + $getVisits = $this->visitsHelper->visitsForDomain( + $expectedDomain, + Argument::type(VisitsParams::class), + $apiKey, + )->willReturn(new Paginator(new ArrayAdapter([]))); + + $response = $this->action->handle( + ServerRequestFactory::fromGlobals()->withAttribute('domain', $providedDomain) + ->withAttribute(ApiKey::class, $apiKey), + ); + + self::assertEquals(200, $response->getStatusCode()); + $getVisits->shouldHaveBeenCalledOnce(); + } + + public function provideDomainAuthorities(): iterable + { + yield 'no default domain' => ['foo.com', 'foo.com']; + yield 'default domain' => ['the_default.com', 'DEFAULT']; + yield 'DEFAULT keyword' => ['DEFAULT', 'DEFAULT']; + } +}