Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit d2a0312

Browse files
committed
MAGETWO-65105: Unhold on "Approved" guarantee status
1 parent 5fb868d commit d2a0312

File tree

3 files changed

+104
-0
lines changed

3 files changed

+104
-0
lines changed

Model/CaseServices/UpdatingServiceTest.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Magento\Framework\App\ResourceConnection;
1010
use Magento\Sales\Api\Data\OrderStatusHistoryInterface;
1111
use Magento\Sales\Api\OrderRepositoryInterface;
12+
use Magento\Sales\Model\Order;
1213
use Magento\Signifyd\Api\CaseRepositoryInterface;
1314
use Magento\Signifyd\Api\Data\CaseInterface;
1415
use Magento\Signifyd\Model\MessageGenerators\GeneratorFactory;
@@ -47,6 +48,7 @@ protected function setUp()
4748

4849
/**
4950
* Checks case updating flow and messages in order comments history.
51+
* Also checks that order is unholded when case guarantee disposition is APPROVED.
5052
*
5153
* @covers \Magento\Signifyd\Model\CaseServices\UpdatingService::update
5254
* @magentoDataFixture Magento/Signifyd/_files/case.php
@@ -97,6 +99,7 @@ public function testUpdate()
9799
/** @var OrderRepositoryInterface $orderRepository */
98100
$orderRepository = $this->objectManager->get(OrderRepositoryInterface::class);
99101
$order = $orderRepository->get($caseEntity->getOrderId());
102+
static::assertEquals(Order::STATE_PROCESSING, $order->getState());
100103
$histories = $order->getStatusHistories();
101104
static::assertNotEmpty($histories);
102105

@@ -106,6 +109,63 @@ public function testUpdate()
106109
static::assertEquals("Signifyd Case $caseId has been created for order.", $caseCreationComment->getComment());
107110
}
108111

112+
/**
113+
* Checks that order is holded when case guarantee disposition is DECLINED.
114+
*
115+
* @covers \Magento\Signifyd\Model\CaseServices\UpdatingService::update
116+
* @magentoDataFixture Magento/Signifyd/_files/approved_case.php
117+
*/
118+
public function testOrderStateAfterDeclinedGuaranteeDisposition()
119+
{
120+
$caseId = 123;
121+
$data = [
122+
'caseId' => $caseId,
123+
'orderId' => '100000001',
124+
'guaranteeDisposition' => CaseInterface::GUARANTEE_DECLINED
125+
];
126+
127+
/** @var CaseRepositoryInterface $caseRepository */
128+
$caseRepository = $this->objectManager->get(CaseRepositoryInterface::class);
129+
$caseEntity = $caseRepository->getByCaseId($caseId);
130+
131+
$this->service->update($caseEntity, $data);
132+
133+
/** @var OrderRepositoryInterface $orderRepository */
134+
$orderRepository = $this->objectManager->get(OrderRepositoryInterface::class);
135+
$order = $orderRepository->get($caseEntity->getOrderId());
136+
137+
static::assertEquals(Order::STATE_HOLDED, $order->getState());
138+
}
139+
140+
/**
141+
* Checks that order doesn't become holded
142+
* when previous case guarantee disposition was DECLINED
143+
* and webhook without guarantee disposition was received.
144+
*
145+
* @covers \Magento\Signifyd\Model\CaseServices\UpdatingService::update
146+
* @magentoDataFixture Magento/Signifyd/_files/declined_case.php
147+
*/
148+
public function testOrderStateAfterWebhookWithoutGuaranteeDisposition()
149+
{
150+
$caseId = 123;
151+
$data = [
152+
'caseId' => $caseId,
153+
'orderId' => '100000001'
154+
];
155+
156+
/** @var CaseRepositoryInterface $caseRepository */
157+
$caseRepository = $this->objectManager->get(CaseRepositoryInterface::class);
158+
$caseEntity = $caseRepository->getByCaseId($caseId);
159+
160+
$this->service->update($caseEntity, $data);
161+
162+
/** @var OrderRepositoryInterface $orderRepository */
163+
$orderRepository = $this->objectManager->get(OrderRepositoryInterface::class);
164+
$order = $orderRepository->get($caseEntity->getOrderId());
165+
166+
static::assertEquals(Order::STATE_PROCESSING, $order->getState());
167+
}
168+
109169
/**
110170
* Returns value of signifyd_guarantee_status column from sales order grid
111171
*

_files/case.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@
33
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
use Magento\Sales\Api\OrderManagementInterface;
67
use Magento\Signifyd\Api\CaseRepositoryInterface;
78
use Magento\Signifyd\Api\Data\CaseInterface;
89
use Magento\Signifyd\Api\Data\CaseInterfaceFactory;
910

1011
require __DIR__ . '/order_with_customer_and_two_simple_products.php';
1112

13+
/** @var OrderManagementInterface $orderManagement */
14+
$orderManagement = $objectManager->create(OrderManagementInterface::class);
15+
$orderManagement->hold($order->getEntityId());
16+
1217
/** @var CaseInterfaceFactory $caseFactory */
1318
$caseFactory = $objectManager->get(CaseInterfaceFactory::class);
1419

@@ -28,6 +33,7 @@
2833
->setOrderId($order->getEntityId())
2934
->setAssociatedTeam($associatedTeam)
3035
->setReviewDisposition(CaseInterface::DISPOSITION_GOOD)
36+
->setGuaranteeDisposition(CaseInterface::GUARANTEE_PENDING)
3137
->setCreatedAt('2016-12-12T15:17:17+0000')
3238
->setUpdatedAt('2016-12-12T19:23:16+0000');
3339

_files/declined_case.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
use Magento\Signifyd\Api\CaseRepositoryInterface;
8+
use Magento\Signifyd\Api\Data\CaseInterface;
9+
use Magento\Signifyd\Api\Data\CaseInterfaceFactory;
10+
11+
require __DIR__ . '/order_with_customer_and_two_simple_products.php';
12+
13+
/** @var CaseInterfaceFactory $caseFactory */
14+
$caseFactory = $objectManager->get(CaseInterfaceFactory::class);
15+
16+
$associatedTeam = [
17+
'teamName' => 'Some Team',
18+
'teamId' => 123,
19+
'getAutoDismiss' => true,
20+
'getTeamDismissalDays' => 3
21+
];
22+
23+
/** @var CaseInterface $case */
24+
$case = $caseFactory->create();
25+
$case->setCaseId(123)
26+
->setGuaranteeEligible(false)
27+
->setGuaranteeDisposition(CaseInterface::GUARANTEE_DECLINED)
28+
->setStatus(CaseInterface::STATUS_PROCESSING)
29+
->setScore(553)
30+
->setOrderId($order->getEntityId())
31+
->setAssociatedTeam($associatedTeam)
32+
->setReviewDisposition(CaseInterface::DISPOSITION_FRAUDULENT)
33+
->setCreatedAt('2016-12-12T15:17:17+0000')
34+
->setUpdatedAt('2016-12-12T19:23:16+0000');
35+
36+
/** @var CaseRepositoryInterface $caseRepository */
37+
$caseRepository = $objectManager->get(CaseRepositoryInterface::class);
38+
$caseRepository->save($case);

0 commit comments

Comments
 (0)