Skip to content

Commit 6866973

Browse files
committed
ACP2E-3774: Concurrent Calls to Reorder GraphQL API - Same Products Added to Different Rows
- add test
1 parent c92a3df commit 6866973

File tree

1 file changed

+124
-0
lines changed

1 file changed

+124
-0
lines changed
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\SalesGraphQl\Test\Unit\Model\Resolver;
9+
10+
use Magento\Framework\Lock\LockManagerInterface;
11+
use Magento\GraphQl\Model\Query\Context;
12+
use Magento\GraphQl\Model\Query\ContextExtension;
13+
use Magento\Sales\Model\OrderFactory;
14+
use Magento\Sales\Model\Reorder\Reorder;
15+
use PHPUnit\Framework\MockObject\MockObject;
16+
use PHPUnit\Framework\TestCase;
17+
use Magento\SalesGraphQl\Model\Resolver\Reorder as Subject;
18+
use Magento\Framework\GraphQl\Config\Element\Field;
19+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
20+
21+
class ReorderTest extends TestCase
22+
{
23+
/**
24+
* @var Subject|MockObject
25+
*/
26+
private $subject;
27+
28+
/**
29+
* @var ContextExtension|MockObject
30+
*/
31+
private $extensionAttributesMock;
32+
33+
/**
34+
* @var Context|MockObject
35+
*/
36+
private $contextMock;
37+
38+
/**
39+
* @var OrderFactory|MockObject
40+
*/
41+
private $orderFactory;
42+
43+
/**
44+
* @var LockManagerInterface|MockObject
45+
*/
46+
private $lockManager;
47+
48+
/**
49+
* @var Reorder|MockObject
50+
*/
51+
private $reorder;
52+
53+
protected function setUp(): void
54+
{
55+
$this->reorder = $this->createMock(Reorder::class);
56+
$this->orderFactory = $this->createMock(OrderFactory::class);
57+
$this->lockManager = $this->createMock(LockManagerInterface::class);
58+
$this->contextMock = $this->createMock(Context::class);
59+
60+
$this->subject = new Subject(
61+
$this->reorder,
62+
$this->orderFactory,
63+
$this->lockManager
64+
);
65+
}
66+
67+
public function testResolve(): void
68+
{
69+
$contextCustomerId = 1;
70+
$orderCustomerId = 1;
71+
$fieldMock = $this->createMock(Field::class);
72+
$resolveInfoMock = $this->createMock(ResolveInfo::class);
73+
$args = ['orderNumber' => '00000010'];
74+
$value = [];
75+
76+
$this->extensionAttributesMock = $this->getMockBuilder(ContextExtension::class)
77+
->disableOriginalConstructor()
78+
->getMock();
79+
$this->extensionAttributesMock->expects($this->once())
80+
->method('getIsCustomer')
81+
->willReturn(true);
82+
83+
$store = $this->createMock(\Magento\Store\Api\Data\StoreInterface::class);
84+
$store->expects($this->once())
85+
->method('getId')
86+
->willReturn(1);
87+
$this->extensionAttributesMock->expects($this->once())
88+
->method('getStore')
89+
->willReturn($store);
90+
91+
$this->contextMock->expects($this->exactly(2))
92+
->method('getExtensionAttributes')
93+
->willReturn($this->extensionAttributesMock);
94+
95+
$this->contextMock->expects($this->once())
96+
->method('getUserId')
97+
->willReturn($contextCustomerId);
98+
99+
$order = $this->createMock(\Magento\Sales\Model\Order::class);
100+
$order->expects($this->once())
101+
->method('loadByIncrementIdAndStoreId')
102+
->willReturnSelf();
103+
$order->expects($this->once())
104+
->method('getCustomerId')
105+
->willReturn($orderCustomerId);
106+
$this->orderFactory->expects($this->once())
107+
->method('create')
108+
->willReturn($order);
109+
110+
$this->lockManager->expects($this->once())
111+
->method('lock')
112+
->willReturn(true);
113+
$this->lockManager->expects($this->once())
114+
->method('unlock')
115+
->willReturn(true);
116+
117+
$result = $this->subject->resolve($fieldMock, $this->contextMock, $resolveInfoMock, $value, $args);
118+
119+
$this->assertIsArray($result);
120+
$this->assertArrayHasKey('cart', $result);
121+
$this->assertArrayHasKey('userInputErrors', $result);
122+
$this->assertEmpty($result['userInputErrors']);
123+
}
124+
}

0 commit comments

Comments
 (0)