|
7 | 7 |
|
8 | 8 | namespace Magento\SalesGraphQl\Test\Unit\Model\Resolver;
|
9 | 9 |
|
| 10 | +use Magento\Framework\Exception\LocalizedException; |
10 | 11 | use Magento\Framework\Lock\LockManagerInterface;
|
11 | 12 | use Magento\GraphQl\Model\Query\Context;
|
12 | 13 | use Magento\GraphQl\Model\Query\ContextExtensionInterface;
|
@@ -68,13 +69,55 @@ protected function setUp(): void
|
68 | 69 |
|
69 | 70 | public function testResolve(): void
|
70 | 71 | {
|
71 |
| - $contextCustomerId = 1; |
72 |
| - $orderCustomerId = 1; |
73 | 72 | $fieldMock = $this->createMock(Field::class);
|
74 | 73 | $resolveInfoMock = $this->createMock(ResolveInfo::class);
|
75 | 74 | $args = ['orderNumber' => '00000010'];
|
76 | 75 | $value = [];
|
77 | 76 |
|
| 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 | + |
78 | 121 | $this->extensionAttributesMock = $this->getMockBuilder(ContextExtensionInterface::class)
|
79 | 122 | ->disableOriginalConstructor()
|
80 | 123 | ->addMethods(['getIsCustomer', 'getStore'])
|
@@ -109,19 +152,5 @@ public function testResolve(): void
|
109 | 152 | $this->orderFactory->expects($this->once())
|
110 | 153 | ->method('create')
|
111 | 154 | ->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']); |
126 | 155 | }
|
127 | 156 | }
|
0 commit comments