From 36e4a0dd325ceffcb01a18ed11c7b2314eecbe0c Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sat, 22 May 2021 09:41:12 +0200 Subject: [PATCH] Added tests for findCrawlableShortCodes --- .../Repository/ShortUrlRepositoryTest.php | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/module/Core/test-db/Repository/ShortUrlRepositoryTest.php b/module/Core/test-db/Repository/ShortUrlRepositoryTest.php index cf082d85..bd5b22d4 100644 --- a/module/Core/test-db/Repository/ShortUrlRepositoryTest.php +++ b/module/Core/test-db/Repository/ShortUrlRepositoryTest.php @@ -436,4 +436,37 @@ class ShortUrlRepositoryTest extends DatabaseTestCase self::assertNull($this->repo->findOneByImportedUrl($buildImported('my-cool-slug', 'doma.in'))); self::assertNull($this->repo->findOneByImportedUrl($buildImported('another-slug'))); } + + /** @test */ + public function findCrawlableShortCodesReturnsExpectedResult(): void + { + $createShortUrl = fn (bool $crawlable) => ShortUrl::fromMeta( + ShortUrlMeta::fromRawData(['crawlable' => $crawlable, 'longUrl' => 'foo.com']), + ); + + $shortUrl1 = $createShortUrl(true); + $this->getEntityManager()->persist($shortUrl1); + $shortUrl2 = $createShortUrl(false); + $this->getEntityManager()->persist($shortUrl2); + $shortUrl3 = $createShortUrl(true); + $this->getEntityManager()->persist($shortUrl3); + $shortUrl4 = $createShortUrl(true); + $this->getEntityManager()->persist($shortUrl4); + $shortUrl5 = $createShortUrl(false); + $this->getEntityManager()->persist($shortUrl5); + $this->getEntityManager()->flush(); + + $iterable = $this->repo->findCrawlableShortCodes(); + $results = []; + foreach ($iterable as $shortCode) { + $results[] = $shortCode; + } + + self::assertCount(3, $results); + self::assertContains($shortUrl1->getShortCode(), $results); + self::assertContains($shortUrl3->getShortCode(), $results); + self::assertContains($shortUrl4->getShortCode(), $results); + self::assertNotContains($shortUrl2->getShortCode(), $results); + self::assertNotContains($shortUrl5->getShortCode(), $results); + } }