-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CC-34501: Initialisation Order Amendment Process (#11163)
CC-34501 Initialisation Order Amendment Process
- Loading branch information
Showing
7 changed files
with
262 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved. | ||
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. | ||
*/ | ||
|
||
namespace Spryker\Zed\Oms\Business\Checker; | ||
|
||
use Generated\Shared\Transfer\OrderItemFilterTransfer; | ||
use Generated\Shared\Transfer\OrderTransfer; | ||
use Spryker\Zed\Oms\Persistence\OmsRepositoryInterface; | ||
|
||
class OrderChecker implements OrderCheckerInterface | ||
{ | ||
/** | ||
* @var \Spryker\Zed\Oms\Business\Checker\FlagCheckerInterface | ||
*/ | ||
protected FlagCheckerInterface $flagChecker; | ||
|
||
/** | ||
* @var \Spryker\Zed\Oms\Persistence\OmsRepositoryInterface | ||
*/ | ||
protected OmsRepositoryInterface $omsRepository; | ||
|
||
/** | ||
* @param \Spryker\Zed\Oms\Business\Checker\FlagCheckerInterface $flagChecker | ||
* @param \Spryker\Zed\Oms\Persistence\OmsRepositoryInterface $omsRepository | ||
*/ | ||
public function __construct(FlagCheckerInterface $flagChecker, OmsRepositoryInterface $omsRepository) | ||
{ | ||
$this->flagChecker = $flagChecker; | ||
$this->omsRepository = $omsRepository; | ||
} | ||
|
||
/** | ||
* @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer | ||
* @param string $flag | ||
* | ||
* @return bool | ||
*/ | ||
public function areOrderItemsSatisfiedByFlag(OrderTransfer $orderTransfer, string $flag): bool | ||
{ | ||
$orderItemFilterTransfer = $this->createOrderItemFilterTransfer($orderTransfer); | ||
$itemTransfers = $this->omsRepository->getOrderItems($orderItemFilterTransfer); | ||
|
||
return $this->flagChecker->hasOrderItemsFlag($itemTransfers, $flag); | ||
} | ||
|
||
/** | ||
* @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer | ||
* | ||
* @return \Generated\Shared\Transfer\OrderItemFilterTransfer | ||
*/ | ||
protected function createOrderItemFilterTransfer(OrderTransfer $orderTransfer): OrderItemFilterTransfer | ||
{ | ||
$orderItemFilterTransfer = new OrderItemFilterTransfer(); | ||
if ($orderTransfer->getOrderReference()) { | ||
return $orderItemFilterTransfer->addOrderReference($orderTransfer->getOrderReferenceOrFail()); | ||
} | ||
|
||
return $orderItemFilterTransfer->addSalesOrderId($orderTransfer->getIdSalesOrderOrFail()); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/Spryker/Zed/Oms/Business/Checker/OrderCheckerInterface.php
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,21 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved. | ||
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. | ||
*/ | ||
|
||
namespace Spryker\Zed\Oms\Business\Checker; | ||
|
||
use Generated\Shared\Transfer\OrderTransfer; | ||
|
||
interface OrderCheckerInterface | ||
{ | ||
/** | ||
* @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer | ||
* @param string $flag | ||
* | ||
* @return bool | ||
*/ | ||
public function areOrderItemsSatisfiedByFlag(OrderTransfer $orderTransfer, string $flag): bool; | ||
} |
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
130 changes: 130 additions & 0 deletions
130
tests/SprykerTest/Zed/Oms/Business/OmsFacade/AreOrderItemsSatisfiedByFlagTest.php
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,130 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved. | ||
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. | ||
*/ | ||
|
||
namespace SprykerTest\Zed\Oms\Business\OmsFacade; | ||
|
||
use Codeception\Test\Unit; | ||
use Generated\Shared\Transfer\OrderTransfer; | ||
use Spryker\Shared\Kernel\Transfer\Exception\NullValueException; | ||
use SprykerTest\Zed\Oms\OmsBusinessTester; | ||
|
||
/** | ||
* Auto-generated group annotations | ||
* | ||
* @group SprykerTest | ||
* @group Zed | ||
* @group Oms | ||
* @group Business | ||
* @group OmsFacade | ||
* @group AreOrderItemsSatisfiedByFlagTest | ||
* Add your own group annotations below this line | ||
*/ | ||
class AreOrderItemsSatisfiedByFlagTest extends Unit | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected const ORDER_ITEM_STATUS_CANCELLED = 'cancelled'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected const ORDER_ITEM_FLAGGED_EXCLUDE_FROM_CUSTOMER = 'exclude from customer'; | ||
|
||
/** | ||
* @var \SprykerTest\Zed\Oms\OmsBusinessTester | ||
*/ | ||
protected OmsBusinessTester $tester; | ||
|
||
/** | ||
* @return void | ||
*/ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->tester->configureTestStateMachine([OmsBusinessTester::DEFAULT_OMS_PROCESS_NAME]); | ||
} | ||
|
||
/** | ||
* @return void | ||
*/ | ||
public function testShouldReturnTrueWhenOrderReferenceIsProvidedAndAllOrderItemsSatisfiedByFlag(): void | ||
{ | ||
// Arrange | ||
$orderTransfer = $this->tester->createOrderByStateMachineProcessName(OmsBusinessTester::DEFAULT_OMS_PROCESS_NAME); | ||
$itemTransfer = $orderTransfer->getItems(); | ||
$this->tester->setItemState($itemTransfer->offsetGet(0)->getIdSalesOrderItem(), static::ORDER_ITEM_STATUS_CANCELLED); | ||
$this->tester->setItemState($itemTransfer->offsetGet(1)->getIdSalesOrderItem(), static::ORDER_ITEM_STATUS_CANCELLED); | ||
|
||
// Act | ||
$result = $this->tester->getFacade()->areOrderItemsSatisfiedByFlag( | ||
(new OrderTransfer())->setOrderReference($orderTransfer->getOrderReferenceOrFail()), | ||
static::ORDER_ITEM_FLAGGED_EXCLUDE_FROM_CUSTOMER, | ||
); | ||
|
||
// Assert | ||
$this->assertTrue($result); | ||
} | ||
|
||
/** | ||
* @return void | ||
*/ | ||
public function testShouldReturnTrueWhenIdSalesOrderIsProvidedAndAllOrderItemsSatisfiedByFlag(): void | ||
{ | ||
// Arrange | ||
$orderTransfer = $this->tester->createOrderByStateMachineProcessName(OmsBusinessTester::DEFAULT_OMS_PROCESS_NAME); | ||
$itemTransfer = $orderTransfer->getItems(); | ||
$this->tester->setItemState($itemTransfer->offsetGet(0)->getIdSalesOrderItem(), static::ORDER_ITEM_STATUS_CANCELLED); | ||
$this->tester->setItemState($itemTransfer->offsetGet(1)->getIdSalesOrderItem(), static::ORDER_ITEM_STATUS_CANCELLED); | ||
|
||
// Act | ||
$result = $this->tester->getFacade()->areOrderItemsSatisfiedByFlag( | ||
(new OrderTransfer())->setIdSalesOrder($orderTransfer->getIdSalesOrderOrFail()), | ||
static::ORDER_ITEM_FLAGGED_EXCLUDE_FROM_CUSTOMER, | ||
); | ||
|
||
// Assert | ||
$this->assertTrue($result); | ||
} | ||
|
||
/** | ||
* @return void | ||
*/ | ||
public function testShouldReturnFalseWhenAtLeastOneOrderItemIsNotSatisfiedByFlag(): void | ||
{ | ||
// Arrange | ||
$orderTransfer = $this->tester->createOrderByStateMachineProcessName(OmsBusinessTester::DEFAULT_OMS_PROCESS_NAME); | ||
$itemTransfer = $orderTransfer->getItems(); | ||
$this->tester->setItemState($itemTransfer->offsetGet(0)->getIdSalesOrderItem(), static::ORDER_ITEM_STATUS_CANCELLED); | ||
|
||
// Act | ||
$result = $this->tester->getFacade()->areOrderItemsSatisfiedByFlag( | ||
$orderTransfer, | ||
static::ORDER_ITEM_FLAGGED_EXCLUDE_FROM_CUSTOMER, | ||
); | ||
|
||
// Assert | ||
$this->assertFalse($result); | ||
} | ||
|
||
/** | ||
* @return void | ||
*/ | ||
public function testThrowsExceptionWhenOrderReferenceAndIdSalesOrderAreNotProvided(): void | ||
{ | ||
// Assert | ||
$this->expectException(NullValueException::class); | ||
$this->expectExceptionMessage(sprintf('Property "idSalesOrder" of transfer `%s` is null.', OrderTransfer::class)); | ||
|
||
// Act | ||
$result = $this->tester->getFacade()->areOrderItemsSatisfiedByFlag( | ||
new OrderTransfer(), | ||
static::ORDER_ITEM_FLAGGED_EXCLUDE_FROM_CUSTOMER, | ||
); | ||
} | ||
} |