2026-06-14 21:32:07 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2026-10-01 10:50:32 +02:00
|
|
|
use App\Dto\ShopDto;
|
2026-06-14 21:32:07 +02:00
|
|
|
use App\Services\MapUrlService;
|
|
|
|
|
use Domain\Models\ValueObjects\DeliveryAddress;
|
|
|
|
|
|
|
|
|
|
covers(MapUrlService::class);
|
|
|
|
|
|
|
|
|
|
describe('MapUrlService', function () {
|
|
|
|
|
it('generates an OpenStreetMap URL when coordinates are present', function () {
|
|
|
|
|
// GIVEN
|
|
|
|
|
$service = new MapUrlService();
|
|
|
|
|
$address = new DeliveryAddress(
|
|
|
|
|
name: 'My Shop',
|
|
|
|
|
address: '123 Test St',
|
|
|
|
|
postcode: '12345',
|
|
|
|
|
city: 'Test City',
|
|
|
|
|
phone: null,
|
|
|
|
|
latitude: '48.8566',
|
|
|
|
|
longitude: '2.3522',
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// WHEN
|
|
|
|
|
$url = $service->generateUrl($address);
|
|
|
|
|
|
|
|
|
|
// THEN
|
|
|
|
|
expect($url)->toBe('https://www.openstreetmap.org/?mlat=48.8566&mlon=2.3522#map=16/48.8566/2.3522');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('generates a Google Maps URL when coordinates are missing', function () {
|
|
|
|
|
// GIVEN
|
|
|
|
|
$service = new MapUrlService();
|
|
|
|
|
$address = new DeliveryAddress(
|
|
|
|
|
name: 'My Shop',
|
|
|
|
|
address: '123 Test St',
|
|
|
|
|
postcode: '12345',
|
|
|
|
|
city: 'Test City',
|
|
|
|
|
phone: null,
|
|
|
|
|
latitude: null,
|
|
|
|
|
longitude: null,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// WHEN
|
|
|
|
|
$url = $service->generateUrl($address);
|
|
|
|
|
|
|
|
|
|
// THEN
|
|
|
|
|
$query = urlencode('My Shop 123 Test St 12345 Test City');
|
|
|
|
|
expect($url)->toBe("https://maps.google.com/?q={$query}");
|
|
|
|
|
});
|
2026-10-01 10:50:32 +02:00
|
|
|
|
|
|
|
|
it('generates an OpenStreetMap URL for a ShopDto', function () {
|
|
|
|
|
// GIVEN
|
|
|
|
|
$service = new MapUrlService();
|
|
|
|
|
$shopDto = new ShopDto(
|
|
|
|
|
id: 'test-id',
|
|
|
|
|
name: 'DTO Shop',
|
|
|
|
|
address: '456 DTO St',
|
|
|
|
|
postcode: '69001',
|
|
|
|
|
city: 'Lyon',
|
|
|
|
|
phone: null,
|
|
|
|
|
latitude: '45.75',
|
|
|
|
|
longitude: '4.85',
|
|
|
|
|
default: false,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// WHEN
|
|
|
|
|
$url = $service->generateUrl($shopDto);
|
|
|
|
|
|
|
|
|
|
// THEN
|
|
|
|
|
expect($url)->toBe('https://www.openstreetmap.org/?mlat=45.75&mlon=4.85#map=16/45.75/4.85');
|
|
|
|
|
});
|
2026-06-14 21:32:07 +02:00
|
|
|
});
|