Skip to content

Commit

Permalink
Update order shipment data after the draft has been created
Browse files Browse the repository at this point in the history
ISSUE: CS-763
  • Loading branch information
ristokekovic committed Mar 26, 2020
1 parent e70736e commit 715f42c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/BusinessLogic/Tasks/SendDraftTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand All @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/BusinessLogic/Common/ApiResponses/draftResponse.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"reference": "DE00019732CF"
"reference": "test"
}
4 changes: 4 additions & 0 deletions tests/BusinessLogic/Order/ShipmentDraftServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
),
);
}
}
12 changes: 10 additions & 2 deletions tests/BusinessLogic/Tasks/SendDraftTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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()
{
Expand All @@ -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);
Expand Down Expand Up @@ -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')
),
);
}
}

0 comments on commit 715f42c

Please sign in to comment.