-
Notifications
You must be signed in to change notification settings - Fork 0
Apms by region request #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Answear\BoxNowBundle\Enum; | ||
|
||
enum RegionEnum: string | ||
{ | ||
case Croatia = 'hr-HR'; | ||
case Cyprus = 'el-CY'; | ||
case Greece = 'el-GR'; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Answear\BoxNowBundle\Request; | ||
|
||
use Answear\BoxNowBundle\Enum\RegionEnum; | ||
|
||
readonly class GetPickupPointsByRegionRequest implements RequestInterface | ||
{ | ||
/* please use locationapi url */ | ||
private const string ENDPOINT = '/v1/apms_REGION_PLACEHOLDER.json'; | ||
private const string HTTP_METHOD = 'GET'; | ||
|
||
public function __construct(private RegionEnum $region) | ||
{ | ||
} | ||
|
||
public function getEndpoint(): string | ||
{ | ||
return str_replace('REGION_PLACEHOLDER', $this->region->value, self::ENDPOINT); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. a placeholder is better to show what exactly I'm doing |
||
} | ||
|
||
public function getMethod(): string | ||
{ | ||
return self::HTTP_METHOD; | ||
} | ||
|
||
public function getUrlQuery(): ?string | ||
{ | ||
return null; | ||
} | ||
|
||
public function getHeaders(): array | ||
{ | ||
return []; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no authorization required for this, but I'll confirm that |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ public function handleData(array $data): void | |
$this->pickupPoints[] = new PickupPointDTO( | ||
$pickupPoint['id'], | ||
$pickupPoint['state'], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in this response there is no type, only state. |
||
$pickupPoint['state'], | ||
$pickupPoint['name'], | ||
$pickupPoint['addressLine1'], | ||
$pickupPoint['title'] ?? null, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Answear\BoxNowBundle\Tests\Integration\Service; | ||
|
||
use Answear\BoxNowBundle\Enum\RegionEnum; | ||
use Answear\BoxNowBundle\Service\PickupPointService; | ||
use Answear\BoxNowBundle\Tests\Util\FileTestUtil; | ||
use GuzzleHttp\Psr7\Response; | ||
use PHPUnit\Framework\Attributes\Test; | ||
use Symfony\Component\HttpFoundation\Response as SymfonyResponse; | ||
use Webmozart\Assert\InvalidArgumentException; | ||
|
||
class PickupPointByRegionServiceTest extends ServiceTestCase | ||
{ | ||
#[Test] | ||
public function successfulListAllPickupPoints(): void | ||
{ | ||
$this->setClient(withLogger: true); | ||
$service = $this->getService(); | ||
|
||
$this->mockGuzzleResponse( | ||
new Response( | ||
status: SymfonyResponse::HTTP_OK, | ||
body: FileTestUtil::getFileContents(__DIR__ . '/../../data/pickup-points/success-by-region.json') | ||
) | ||
); | ||
|
||
$pickupPoints = $service->getAllByRegion(RegionEnum::Croatia); | ||
$actualData = []; | ||
|
||
foreach ($pickupPoints as $pickupPoint) { | ||
$actualData[] = [ | ||
'id' => $pickupPoint->id, | ||
'type' => $pickupPoint->type, | ||
'name' => $pickupPoint->name, | ||
'address' => $pickupPoint->address, | ||
'title' => $pickupPoint->title, | ||
'image' => $pickupPoint->image, | ||
'latitude' => $pickupPoint->latitude, | ||
'longitude' => $pickupPoint->longitude, | ||
'postalCode' => $pickupPoint->postalCode, | ||
'country' => $pickupPoint->country, | ||
'note' => $pickupPoint->note, | ||
'additionalAddress' => $pickupPoint->additionalAddress, | ||
'expectedDeliveryTime' => $pickupPoint->expectedDeliveryTime, | ||
'region' => $pickupPoint->region, | ||
]; | ||
|
||
self::assertSame( | ||
$pickupPoint->address . ', ' . $pickupPoint->additionalAddress, | ||
$pickupPoint->getFullAddress(', ') | ||
); | ||
} | ||
|
||
$this->assertJsonStringEqualsJsonString( | ||
json_encode($actualData, JSON_THROW_ON_ERROR), | ||
FileTestUtil::getFileContents(__DIR__ . '/../../data/pickup-points/assert-valid-data-by-region.json'), | ||
); | ||
} | ||
|
||
#[Test] | ||
public function invalidPickupPointIdFieldValue(): void | ||
{ | ||
$this->expectException(InvalidArgumentException::class); | ||
$this->expectExceptionMessage('Field id expected to be a string. Got: '); | ||
|
||
$this->setClient(); | ||
$service = $this->getService(); | ||
|
||
$this->mockGuzzleResponse( | ||
new Response( | ||
status: SymfonyResponse::HTTP_OK, | ||
body: FileTestUtil::getFileContents(__DIR__ . '/../../data/pickup-points/invalid-id-field-value.json') | ||
) | ||
); | ||
|
||
$service->getAllByRegion(RegionEnum::Cyprus); | ||
} | ||
|
||
protected function getLoggerStream(): array | ||
{ | ||
return [ | ||
'[BOXNOW] Request - /v1/apms_hr-HR.json' => [ | ||
'endpoint' => '/v1/apms_hr-HR.json', | ||
'uri' => [ | ||
'path' => '/v1/apms_hr-HR.json', | ||
'query' => [], | ||
], | ||
'body' => [], | ||
], | ||
'[BOXNOW] Response - /v1/apms_hr-HR.json' => [ | ||
'endpoint' => '/v1/apms_hr-HR.json', | ||
'uri' => [ | ||
'path' => '/v1/apms_hr-HR.json', | ||
'query' => [], | ||
], | ||
'response' => '--- HUGE CONTENT SKIPPED ---', | ||
], | ||
]; | ||
} | ||
|
||
private function getService(): PickupPointService | ||
{ | ||
return new PickupPointService($this->getClient(), $this->getSerializer()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
[ | ||
{ | ||
"additionalAddress": "Λυκόβρυση", | ||
"address": "Λεωφόρος Σοφοκλή Βενιζέλου 49", | ||
"country": "GR", | ||
"expectedDeliveryTime": "2025-06-27T19:00:00.000Z", | ||
"id": "28", | ||
"image": "https://storage.googleapis.com/boxnow-production-images/images/manager/30_11_2022/69366d64-218f-4575-8f2f-6cf571e5095f", | ||
"latitude": 38.071742, | ||
"longitude": 23.785242, | ||
"name": "ΑΒ Λυκόβρυσης", | ||
"note": "Επί της Λεωφόρου Σοφοκλή Βενιζέλου με κατεύθυνση το Ηράκλειο. Στο κατάστημα του ΑΒ Βασιλόπουλου δεξιά από την είσοδο.", | ||
"postalCode": "14123", | ||
"region": "el-GR", | ||
"title": "Λ. ΣOΦOKΛH BENIZEΛOY 49, 14123", | ||
"type": "apm" | ||
}, | ||
{ | ||
"additionalAddress": "Γαλάτσι", | ||
"address": "Αιγοσθενών 78", | ||
"country": "GR", | ||
"expectedDeliveryTime": "2025-06-27T19:00:00.000Z", | ||
"id": "5143", | ||
"image": "https://storage.googleapis.com/boxnow-production-images/images/operations-manager/07_06_2024/4a62d29d-8510-4b37-955e-fc776c4cbd97", | ||
"latitude": 38.02378602124016, | ||
"longitude": 23.756451726304455, | ||
"name": "e-Mob - Γαλάτσι", | ||
"note": "Επί της οδού Αιγοσθένων, στο κατάστημα e-Mob.", | ||
"postalCode": "11146", | ||
"region": "el-GR", | ||
"title": "AIΓOΣΘENΩN 78, 11146", | ||
"type": "apm" | ||
}, | ||
{ | ||
"additionalAddress": "Λαμία", | ||
"address": "Πύλου 24", | ||
"country": "GR", | ||
"expectedDeliveryTime": "2025-06-27T19:00:00.000Z", | ||
"id": "7417", | ||
"image": "https://storage.googleapis.com/boxnow-production-images/images/operations-manager/27_03_2024/4ccf4a19-1b85-49e9-bf7e-46d2f38b6ad4", | ||
"latitude": 38.8932357729316, | ||
"longitude": 22.41868934381607, | ||
"name": "Γαλαξίας - 1ο ΧΛΜ Λαμίας Καρπενησίου", | ||
"note": "Επί της οδού Πύλου 24, στο Super Market ΓΑΛΑΞΙΑΣ.", | ||
"postalCode": "35100", | ||
"region": "el-GR", | ||
"title": "ΠYΛOY 24, 35100", | ||
"type": "apm" | ||
}, | ||
{ | ||
"additionalAddress": "Μεταμόρφωση", | ||
"address": "Αγ Νεκταρίου 69", | ||
"country": "GR", | ||
"expectedDeliveryTime": "2025-06-27T19:00:00.000Z", | ||
"id": "7427", | ||
"image": "https://storage.googleapis.com/boxnow-production-images/images/operations-manager/15_03_2024/82088a63-e40f-4a5d-8bea-beba68a8ea16", | ||
"latitude": 38.05352105272671, | ||
"longitude": 23.759888047413963, | ||
"name": "Pet Vip Arena Market - Μεταμόρφωση", | ||
"note": "Επί της οδού Αγ. Νεκταρίου, στο κατάστημα Arena Market.", | ||
"postalCode": "14451", | ||
"region": "el-GR", | ||
"title": "AΓ NEKTAPIOY, 14451", | ||
"type": "apm" | ||
}, | ||
{ | ||
"additionalAddress": " Άρτα", | ||
"address": "Κόμβος A5 Ιονίας Οδού & EO Άρτας-Τρικάλων", | ||
"country": "GR", | ||
"expectedDeliveryTime": "2025-06-27T19:00:00.000Z", | ||
"id": "7428", | ||
"image": "https://storage.googleapis.com/boxnow-production-images/images/operations-manager/15_03_2024/dfe5bbe7-6333-4cde-b17a-b96a169690ef", | ||
"latitude": 39.15787014093051, | ||
"longitude": 21.012647900737115, | ||
"name": "ΑΒ Κόμβος Ιονίας Οδού - Άρτα", | ||
"note": "Στη συμβολη Α5 Ιονίας Οδού & ΕΟ Άρτας Τρικάλων, στο Super Market ΑΒ Βασιλόπουλος.", | ||
"postalCode": "47100", | ||
"region": "el-GR", | ||
"title": "KOMBOΣ IONIAΣ OΔOY, 47100", | ||
"type": "apm" | ||
}, | ||
{ | ||
"additionalAddress": "Εύοσμος", | ||
"address": "25ης Μαρτίου 84-86", | ||
"country": "GR", | ||
"expectedDeliveryTime": "2025-06-27T19:00:00.000Z", | ||
"id": "7436", | ||
"image": "https://storage.googleapis.com/boxnow-production-images/images/operations-manager/11_06_2024/23cacf70-98e6-4f00-860d-024c87cd7aad", | ||
"latitude": 40.6725665098987, | ||
"longitude": 22.91599971354653, | ||
"name": "Το παντοπωλείο της Σοφίας - Εύοσμος", | ||
"note": "Επί της οδού 25ης Μαρτίου, στο Παντοπωλείο της Σοφίας.", | ||
"postalCode": "56224", | ||
"region": "el-GR", | ||
"title": "25HΣ MAPTIOY 84-86, 56224", | ||
"type": "apm" | ||
}, | ||
{ | ||
"additionalAddress": "Σταυρούπολη", | ||
"address": "Κ. Κωνσταντινίδη & Αγ. Κωνσταντίνου 15", | ||
"country": "GR", | ||
"expectedDeliveryTime": "2025-06-27T19:00:00.000Z", | ||
"id": "7439", | ||
"image": "https://storage.googleapis.com/boxnow-production-images/images/operations-manager/22_11_2024/90d1d461-5ba5-4102-b9fa-d80326e6b9e8", | ||
"latitude": 40.66777703688724, | ||
"longitude": 22.927759187900392, | ||
"name": "Woodncraft - Σταυρούπολη", | ||
"note": "Στη συμβολή των οδών Κωσταντινίδη και Αγ. Κωσταντίνου, στο κατάστημα WoodNCraft.", | ||
"postalCode": "56431", | ||
"region": "el-GR", | ||
"title": "AΓ KΩNΣTANTINOY 15, 56431", | ||
"type": "apm" | ||
} | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is some
state
like "boxnow-ready"