From 715f42c1278f756c03e0eea1091ad4add2412f96 Mon Sep 17 00:00:00 2001 From: Risto Kekovic Date: Thu, 26 Mar 2020 12:17:58 +0100 Subject: [PATCH] Update order shipment data after the draft has been created ISSUE: CS-763 --- src/BusinessLogic/Tasks/SendDraftTask.php | 7 +++++++ .../Common/ApiResponses/draftResponse.json | 2 +- .../BusinessLogic/Order/ShipmentDraftServiceTest.php | 4 ++++ tests/BusinessLogic/Tasks/SendDraftTaskTest.php | 12 ++++++++++-- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/BusinessLogic/Tasks/SendDraftTask.php b/src/BusinessLogic/Tasks/SendDraftTask.php index 40b58b6b..ae657903 100644 --- a/src/BusinessLogic/Tasks/SendDraftTask.php +++ b/src/BusinessLogic/Tasks/SendDraftTask.php @@ -109,6 +109,7 @@ public function unserialize($serialized) * @throws \Logeecom\Infrastructure\Http\Exceptions\HttpRequestException * @throws \Packlink\BusinessLogic\Http\Exceptions\DraftNotCreatedException * @throws \Packlink\BusinessLogic\Order\Exceptions\OrderNotFound + * @throws \Packlink\BusinessLogic\OrderShipmentDetails\Exceptions\OrderShipmentDetailsNotFound */ public function execute() { @@ -134,6 +135,12 @@ public function execute() $this->reportProgress(85); $this->getOrderService()->setReference($this->orderId, $reference); + $shipment = $this->getProxy()->getShipment($reference); + + if ($shipment) { + $this->getOrderService()->updateShipmentData($shipment); + } + $this->reportProgress(100); } diff --git a/tests/BusinessLogic/Common/ApiResponses/draftResponse.json b/tests/BusinessLogic/Common/ApiResponses/draftResponse.json index 6349a8e1..ccaedd6e 100644 --- a/tests/BusinessLogic/Common/ApiResponses/draftResponse.json +++ b/tests/BusinessLogic/Common/ApiResponses/draftResponse.json @@ -1,3 +1,3 @@ { - "reference": "DE00019732CF" + "reference": "test" } \ No newline at end of file diff --git a/tests/BusinessLogic/Order/ShipmentDraftServiceTest.php b/tests/BusinessLogic/Order/ShipmentDraftServiceTest.php index e51a26e9..e14ff62e 100644 --- a/tests/BusinessLogic/Order/ShipmentDraftServiceTest.php +++ b/tests/BusinessLogic/Order/ShipmentDraftServiceTest.php @@ -304,6 +304,10 @@ private function getMockResponses() new HttpResponse( 200, array(), '{}' ), + // send shipment response + new HttpResponse( + 200, array(), file_get_contents(__DIR__ . '/../Common/ApiResponses/shipment.json') + ), ); } } diff --git a/tests/BusinessLogic/Tasks/SendDraftTaskTest.php b/tests/BusinessLogic/Tasks/SendDraftTaskTest.php index ed784bd1..a16a96a2 100644 --- a/tests/BusinessLogic/Tasks/SendDraftTaskTest.php +++ b/tests/BusinessLogic/Tasks/SendDraftTaskTest.php @@ -27,6 +27,7 @@ use Packlink\BusinessLogic\ShippingMethod\Models\ShippingMethod; use Packlink\BusinessLogic\ShippingMethod\PackageTransformer; use Packlink\BusinessLogic\ShippingMethod\ShippingMethodService; +use Packlink\BusinessLogic\ShippingMethod\Utility\ShipmentStatus; use Packlink\BusinessLogic\Tasks\SendDraftTask; /** @@ -134,6 +135,7 @@ protected function tearDown() * @throws \Logeecom\Infrastructure\Http\Exceptions\HttpRequestException * @throws \Packlink\BusinessLogic\Order\Exceptions\OrderNotFound * @throws \Packlink\BusinessLogic\Http\Exceptions\DraftNotCreatedException + * @throws \Packlink\BusinessLogic\OrderShipmentDetails\Exceptions\OrderShipmentDetailsNotFound */ public function testExecute() { @@ -144,9 +146,11 @@ public function testExecute() $shopOrderService = TestServiceRegister::getService(OrderShipmentDetailsService::CLASS_NAME); $shipmentDetails = $shopOrderService->getDetailsByOrderId('test'); - $this->assertEquals('DE00019732CF', $shipmentDetails->getReference()); + $this->assertEquals('test', $shipmentDetails->getReference()); + $this->assertEquals(15.85, $shipmentDetails->getShippingCost()); + $this->assertEquals(ShipmentStatus::STATUS_PENDING, ShipmentStatus::getStatus($shipmentDetails->getStatus())); // there should be an info message that draft is created. - $this->assertCount(1, $this->shopLogger->loggedMessages); + $this->assertCount(2, $this->shopLogger->loggedMessages); /** @var OrderSendDraftTaskMapService $taskMapService */ $taskMapService = ServiceRegister::getService(OrderSendDraftTaskMapService::CLASS_NAME); @@ -209,6 +213,10 @@ private function getMockResponses() new HttpResponse( 200, array(), '{}' ), + // send shipment response + new HttpResponse( + 200, array(), file_get_contents(__DIR__ . '/../Common/ApiResponses/shipment.json') + ), ); } }