From fdcf88de670524b864af8cefa8f198310a7e72c2 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 25 Oct 2020 12:06:48 +0100 Subject: [PATCH] Added database tests for ShortUrlRepository::importedUrlExists --- .../Repository/ShortUrlRepositoryTest.php | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/module/Core/test-db/Repository/ShortUrlRepositoryTest.php b/module/Core/test-db/Repository/ShortUrlRepositoryTest.php index ad99a9a3..86eb2aa3 100644 --- a/module/Core/test-db/Repository/ShortUrlRepositoryTest.php +++ b/module/Core/test-db/Repository/ShortUrlRepositoryTest.php @@ -17,6 +17,7 @@ use Shlinkio\Shlink\Core\Model\ShortUrlsOrdering; use Shlinkio\Shlink\Core\Model\Visitor; use Shlinkio\Shlink\Core\Repository\ShortUrlRepository; use Shlinkio\Shlink\Core\Util\TagManagerTrait; +use Shlinkio\Shlink\Importer\Model\ImportedShlinkUrl; use Shlinkio\Shlink\TestUtils\DbTest\DatabaseTestCase; use function count; @@ -320,4 +321,26 @@ class ShortUrlRepositoryTest extends DatabaseTestCase $this->repo->findOneMatching('foo', $tags, ShortUrlMeta::fromRawData($meta)), ); } + + /** @test */ + public function importedShortUrlsAreSearchedAsExpected(): void + { + $buildImported = static fn (string $shortCode, ?String $domain = null) => + new ImportedShlinkUrl('', 'foo', [], Chronos::now(), $domain, $shortCode); + + $shortUrlWithoutDomain = ShortUrl::fromImport($buildImported('my-cool-slug'), true); + $this->getEntityManager()->persist($shortUrlWithoutDomain); + + $shortUrlWithDomain = ShortUrl::fromImport($buildImported('another-slug', 'doma.in'), true); + $this->getEntityManager()->persist($shortUrlWithDomain); + + $this->getEntityManager()->flush(); + + self::assertTrue($this->repo->importedUrlExists($buildImported('my-cool-slug'))); + self::assertTrue($this->repo->importedUrlExists($buildImported('another-slug', 'doma.in'))); + self::assertFalse($this->repo->importedUrlExists($buildImported('non-existing-slug'))); + self::assertFalse($this->repo->importedUrlExists($buildImported('non-existing-slug', 'doma.in'))); + self::assertFalse($this->repo->importedUrlExists($buildImported('my-cool-slug', 'doma.in'))); + self::assertFalse($this->repo->importedUrlExists($buildImported('another-slug'))); + } }