Skip to content

Commit 45a88d3

Browse files
committed
ACP2E-3774: Concurrent Calls to Reorder GraphQL API - Same Products Added to Different Rows
1 parent 30b9ec6 commit 45a88d3

File tree

1 file changed

+45
-16
lines changed

1 file changed

+45
-16
lines changed

app/code/Magento/SalesGraphQl/Test/Unit/Model/Resolver/ReorderTest.php

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Magento\SalesGraphQl\Test\Unit\Model\Resolver;
99

10+
use Magento\Framework\Exception\LocalizedException;
1011
use Magento\Framework\Lock\LockManagerInterface;
1112
use Magento\GraphQl\Model\Query\Context;
1213
use Magento\GraphQl\Model\Query\ContextExtensionInterface;
@@ -68,13 +69,55 @@ protected function setUp(): void
6869

6970
public function testResolve(): void
7071
{
71-
$contextCustomerId = 1;
72-
$orderCustomerId = 1;
7372
$fieldMock = $this->createMock(Field::class);
7473
$resolveInfoMock = $this->createMock(ResolveInfo::class);
7574
$args = ['orderNumber' => '00000010'];
7675
$value = [];
7776

77+
$this->prepareCommonFlow();
78+
79+
$this->lockManager->expects($this->once())
80+
->method('lock')
81+
->willReturn(true);
82+
$this->lockManager->expects($this->once())
83+
->method('unlock')
84+
->willReturn(true);
85+
86+
$result = $this->subject->resolve($fieldMock, $this->contextMock, $resolveInfoMock, $value, $args);
87+
88+
$this->assertIsArray($result);
89+
$this->assertArrayHasKey('cart', $result);
90+
$this->assertArrayHasKey('userInputErrors', $result);
91+
$this->assertEmpty($result['userInputErrors']);
92+
}
93+
94+
public function testResolveLockedAndThrowsError(): void
95+
{
96+
$fieldMock = $this->createMock(Field::class);
97+
$resolveInfoMock = $this->createMock(ResolveInfo::class);
98+
$args = ['orderNumber' => '00000010'];
99+
$value = [];
100+
101+
$this->prepareCommonFlow();
102+
103+
$this->lockManager->expects($this->once())
104+
->method('lock')
105+
->willReturn(false);
106+
$this->lockManager->expects($this->never())
107+
->method('unlock');
108+
109+
$exceptionMessage = 'Sorry, there has been an error processing your request. Please try again later.';
110+
$this->expectException(LocalizedException::class);
111+
$this->expectExceptionMessage($exceptionMessage);
112+
113+
$result = $this->subject->resolve($fieldMock, $this->contextMock, $resolveInfoMock, $value, $args);
114+
}
115+
116+
private function prepareCommonFlow()
117+
{
118+
$contextCustomerId = 1;
119+
$orderCustomerId = 1;
120+
78121
$this->extensionAttributesMock = $this->getMockBuilder(ContextExtensionInterface::class)
79122
->disableOriginalConstructor()
80123
->addMethods(['getIsCustomer', 'getStore'])
@@ -109,19 +152,5 @@ public function testResolve(): void
109152
$this->orderFactory->expects($this->once())
110153
->method('create')
111154
->willReturn($order);
112-
113-
$this->lockManager->expects($this->once())
114-
->method('lock')
115-
->willReturn(true);
116-
$this->lockManager->expects($this->once())
117-
->method('unlock')
118-
->willReturn(true);
119-
120-
$result = $this->subject->resolve($fieldMock, $this->contextMock, $resolveInfoMock, $value, $args);
121-
122-
$this->assertIsArray($result);
123-
$this->assertArrayHasKey('cart', $result);
124-
$this->assertArrayHasKey('userInputErrors', $result);
125-
$this->assertEmpty($result['userInputErrors']);
126155
}
127156
}

0 commit comments

Comments
 (0)