diff --git a/module/Rest/test/Action/ShortUrl/DeleteShortUrlVisitsActionTest.php b/module/Rest/test/Action/ShortUrl/DeleteShortUrlVisitsActionTest.php new file mode 100644 index 00000000..8ff727c6 --- /dev/null +++ b/module/Rest/test/Action/ShortUrl/DeleteShortUrlVisitsActionTest.php @@ -0,0 +1,56 @@ +deleter = $this->createMock(ShortUrlVisitsDeleterInterface::class); + $this->action = new DeleteShortUrlVisitsAction($this->deleter); + } + + #[Test, DataProvider('provideVisitsCounts')] + public function visitsAreDeletedForShortUrl(int $visitsCount): void + { + $apiKey = ApiKey::create(); + $request = ServerRequestFactory::fromGlobals()->withAttribute(ApiKey::class, $apiKey) + ->withAttribute('shortCode', 'foo'); + + $this->deleter->expects($this->once())->method('deleteShortUrlVisits')->with( + ShortUrlIdentifier::fromShortCodeAndDomain('foo'), + $apiKey, + )->willReturn(new BulkDeleteResult($visitsCount)); + + /** @var JsonResponse $resp */ + $resp = $this->action->handle($request); + $payload = $resp->getPayload(); + + self::assertEquals(['deletedVisits' => $visitsCount], $payload); + } + + public static function provideVisitsCounts(): iterable + { + yield '1' => [1]; + yield '0' => [0]; + yield '300' => [300]; + yield '1234' => [1234]; + } +}