Added test covering case in which the original address is provided when locating visits

This commit is contained in:
Alejandro Celaya 2020-03-22 11:12:30 +01:00
parent 3fef4b4a28
commit fdd8efc12d

View file

@ -130,13 +130,16 @@ class LocateShortUrlVisitTest extends TestCase
yield 'localhost' => [new Visit($shortUrl, new Visitor('', '', IpAddress::LOCALHOST))];
}
/** @test */
public function locatableVisitsResolveToLocation(): void
/**
* @test
* @dataProvider provideIpAddresses
*/
public function locatableVisitsResolveToLocation(string $anonymizedIpAddress, ?string $originalIpAddress): void
{
$ipAddr = '1.2.3.0';
$ipAddr = $originalIpAddress ?? $anonymizedIpAddress;
$visit = new Visit(new ShortUrl(''), new Visitor('', '', $ipAddr));
$location = new Location('', '', '', '', 0.0, 0.0, '');
$event = new ShortUrlVisited('123');
$event = new ShortUrlVisited('123', $originalIpAddress);
$findVisit = $this->em->find(Visit::class, '123')->willReturn($visit);
$flush = $this->em->flush()->will(function (): void {
@ -155,6 +158,12 @@ class LocateShortUrlVisitTest extends TestCase
$dispatch->shouldHaveBeenCalledOnce();
}
public function provideIpAddresses(): iterable
{
yield 'no original IP address' => ['1.2.3.0', null];
yield 'original IP address' => ['1.2.3.0', '1.2.3.4'];
}
/** @test */
public function errorWhenUpdatingGeoLiteWithExistingCopyLogsWarning(): void
{