-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #75 from storekeeper-company/CU-86950b4bv_Order-sh…
…ipment-sync-M2---SK-Integration-test-queue-removed CU-8694eqmtm Adjusted order creation integration test
- Loading branch information
Showing
4 changed files
with
163 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?php | ||
|
||
namespace StoreKeeper\StoreKeeper\Test\Integration; | ||
|
||
use Magento\Framework\Event; | ||
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; | ||
use Magento\TestFramework\Helper\Bootstrap; | ||
|
||
/** | ||
* @magentoDbIsolation enabled | ||
*/ | ||
class ShipmentCreationTest extends AbstractTestCase | ||
{ | ||
|
||
const SHIPMENT_ID = 1; | ||
|
||
const SHIPMENT_QUEUE = [ | ||
"order_id" => "1", | ||
"storekeeper_id" => "200", | ||
"store_id" => "1", | ||
"items" => [["id" => "999", "quantity" => 1]] | ||
]; | ||
|
||
protected $shipmentFactory; | ||
protected $shipmentRepository; | ||
protected $shipmentObserver; | ||
protected $json; | ||
protected $apiOrdersMock; | ||
protected $shipment; | ||
protected $orderApiClientMock; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
$objectManager = new ObjectManager($this); | ||
$this->shipmentFactory = Bootstrap::getObjectManager()->create(\Magento\Sales\Model\Order\ShipmentFactory::class); | ||
$this->shipmentRepository = Bootstrap::getObjectManager()->create(\Magento\Sales\Model\Order\ShipmentRepository::class); | ||
$this->json = Bootstrap::getObjectManager()->create(\Magento\Framework\Serialize\Serializer\Json::class); | ||
$this->apiOrdersMock = $this->createMock(\StoreKeeper\StoreKeeper\Helper\Api\Orders::class); | ||
$this->orderApiClientMock = $this->createMock(\StoreKeeper\StoreKeeper\Api\OrderApiClient::class); | ||
|
||
$this->orderApiClientMock->method('newOrderShipment')->willReturn(self::SHIPMENT_ID); | ||
$this->apiOrdersMock->method('getStoreKeeperOrder')->willReturn( | ||
['order_items' => [0 => ['is_shipping' => false, 'id' => 999, 'quantity' => 1]]] | ||
); | ||
$this->apiOrdersMock->method('allowShipmnetCreation')->willReturn(true); | ||
|
||
$this->shipment = $objectManager->getObject( | ||
\StoreKeeper\StoreKeeper\Model\OrderSync\Shipment::class, | ||
[ | ||
'orderApiClient' => $this->orderApiClientMock, | ||
'orderRepository' => $this->orderRepository, | ||
'orderResource' => $this->orderResource | ||
] | ||
); | ||
|
||
$this->shipmentObserver = $objectManager->getObject( | ||
\StoreKeeper\StoreKeeper\Observers\SalesOrderShipmentSaveBefore::class, | ||
[ | ||
'json' => $this->json, | ||
'apiOrders' => $this->apiOrdersMock, | ||
'shipment' => $this->shipment | ||
] | ||
); | ||
} | ||
|
||
/** | ||
* @magentoDataFixture StoreKeeper_StoreKeeper::Test/Integration/_files/order_shipping.php | ||
* @magentoDbIsolation enabled | ||
*/ | ||
public function testShipmentCreation() | ||
{ | ||
$existingOrder = Bootstrap::getObjectManager()->create(\Magento\Sales\Model\Order::class) | ||
->loadByIncrementId('100000001'); | ||
$shipment = $existingOrder->getShipmentsCollection()->getFirstItem(); | ||
|
||
//Mock and trigger shipment_save_after event with current order shipment record | ||
$observer = $this->getMockBuilder(Event\Observer::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$observer->method('getEvent')->willReturn(new Event()); | ||
$observer->getEvent()->setData('shipment', $shipment); | ||
$this->shipmentObserver->execute($observer); | ||
|
||
//Reload order with fresh data | ||
$existingOrder = Bootstrap::getObjectManager()->create(\Magento\Sales\Model\Order::class) | ||
->loadByIncrementId('100000001'); | ||
|
||
//Assert that storekeeper shipment id were generated and assigned to order during consumer run | ||
$this->assertEquals(self::SHIPMENT_ID, $existingOrder->getStorekeeperShipmentId()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
use Magento\TestFramework\Helper\Bootstrap; | ||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver; | ||
|
||
Resolver::getInstance()->requireDataFixture('Magento/Sales/_files/order.php'); | ||
|
||
$objectManager = Bootstrap::getObjectManager(); | ||
/** @var \Magento\Sales\Model\Order $order */ | ||
$order = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Sales\Model\Order::class); | ||
$order->loadByIncrementId('100000001'); | ||
|
||
$order->setData( | ||
'base_to_global_rate', | ||
2 | ||
)->setData( | ||
'base_shipping_amount', | ||
20 | ||
)->setData( | ||
'base_shipping_canceled', | ||
2 | ||
)->setData( | ||
'base_shipping_invoiced', | ||
20 | ||
)->setData( | ||
'base_shipping_refunded', | ||
3 | ||
)->setData( | ||
'is_virtual', | ||
0 | ||
)->setData( | ||
'storekeeper_id', | ||
200 | ||
)->setData( | ||
'order_detached', | ||
true | ||
)->save(); | ||
|
||
$orderItems = $order->getItems(); | ||
/** @var \Magento\Sales\Api\Data\OrderItemInterface $orderItem */ | ||
$orderItem = array_values($orderItems)[0]; | ||
|
||
/** @var \Magento\Sales\Api\Data\ShipmentItemCreationInterface $shipmentItem */ | ||
$invoiceItem = $objectManager->create(\Magento\Sales\Api\Data\InvoiceItemCreationInterface::class); | ||
$invoiceItem->setOrderItemId($orderItem->getItemId()); | ||
$invoiceItem->setQty($orderItem->getQtyOrdered()); | ||
/** @var \Magento\Sales\Api\InvoiceOrderInterface $invoiceOrder */ | ||
$invoiceOrder = $objectManager->create(\Magento\Sales\Api\InvoiceOrderInterface::class); | ||
$invoiceOrder->execute($order->getEntityId(), false, [$invoiceItem]); | ||
|
||
/** @var \Magento\Sales\Api\Data\ShipmentItemCreationInterface $shipmentItem */ | ||
$shipmentItem = $objectManager->create(\Magento\Sales\Api\Data\ShipmentItemCreationInterface::class); | ||
$shipmentItem->setOrderItemId($orderItem->getItemId()); | ||
$shipmentItem->setQty($orderItem->getQtyOrdered()); | ||
/** @var \Magento\Sales\Api\ShipOrderInterface $shipOrder */ | ||
$shipOrder = $objectManager->create(\Magento\Sales\Api\ShipOrderInterface::class); | ||
$shipOrder->execute($order->getEntityId(), [$shipmentItem]); |