Skip to content

Commit 7da3895

Browse files
committed
ACP2E-3128: [Cloud] Broken GraphQL call for getPurchaseOrder with node quote
1 parent 11e7d89 commit 7da3895

File tree

2 files changed

+53
-6
lines changed

2 files changed

+53
-6
lines changed

app/code/Magento/QuoteGraphQl/Model/Resolver/MaskedCartId.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,7 @@ private function getQuoteMaskId(int $quoteId): string
9595
*/
9696
private function ensureQuoteMaskExist(int $quoteId): string
9797
{
98-
try {
99-
$maskedId = $this->quoteIdToMaskedQuoteId->execute($quoteId);
100-
} catch (NoSuchEntityException $e) {
101-
$maskedId = '';
102-
}
98+
$maskedId = $this->quoteIdToMaskedQuoteId->execute($quoteId);
10399
if ($maskedId === '') {
104100
$quoteIdMask = $this->quoteIdMaskFactory->create();
105101
$quoteIdMask->setQuoteId($quoteId);

app/code/Magento/QuoteGraphQl/Test/Unit/Model/Resolver/MaskedCartIdTest.php

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace Magento\QuoteGraphQl\Test\Unit\Model\Resolver;
99

1010
use Magento\Framework\Exception\LocalizedException;
11+
use Magento\Framework\Exception\NoSuchEntityException;
1112
use Magento\Framework\GraphQl\Config\Element\Field;
1213
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
1314
use Magento\GraphQl\Model\Query\Context;
@@ -16,7 +17,6 @@
1617
use Magento\Quote\Model\QuoteIdMaskFactory;
1718
use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface;
1819
use Magento\Quote\Model\ResourceModel\Quote\QuoteIdMask as QuoteIdMaskResourceModel;
19-
use Magento\QuoteGraphQl\Model\Resolver\Cart;
2020
use Magento\QuoteGraphQl\Model\Resolver\MaskedCartId;
2121
use PHPUnit\Framework\MockObject\MockObject;
2222
use PHPUnit\Framework\TestCase;
@@ -134,4 +134,55 @@ public function testResolve(): void
134134
->with($this->quoteIdMask);
135135
$this->maskedCartId->resolve($this->fieldMock, $this->contextMock, $this->resolveInfoMock, $this->valueMock);
136136
}
137+
138+
/**
139+
*
140+
* @dataProvider resolveDataProvider
141+
* @param $cartId
142+
* @param $maskedId
143+
* @param $expectedResult
144+
* @return void
145+
* @throws \Exception
146+
*/
147+
public function testResolveForException($cartId, $maskedId, $expectedResult): void
148+
{
149+
$this->valueMock = ['model' => $this->quoteMock];
150+
$this->quoteMock
151+
->expects($this->once())
152+
->method('getId')
153+
->willReturn($cartId);
154+
if ($cartId == 0) {
155+
$this->quoteIdToMaskedQuoteId->method('execute')->with($cartId)->willThrowException(
156+
new NoSuchEntityException(
157+
__(
158+
'No such entity with %fieldName = %fieldValue',
159+
[
160+
'fieldName' => 'quoteId',
161+
'fieldValue' => $cartId
162+
]
163+
)
164+
)
165+
);
166+
$this->expectExceptionMessage('Current user does not have an active cart.');
167+
}
168+
$this->quoteIdToMaskedQuoteId->method('execute')->with($cartId)->willReturn($maskedId);
169+
$result = $this->maskedCartId->resolve(
170+
$this->fieldMock,
171+
$this->contextMock,
172+
$this->resolveInfoMock,
173+
$this->valueMock
174+
);
175+
$this->assertEquals($expectedResult, $result);
176+
}
177+
178+
/**
179+
* @return array
180+
*/
181+
public function resolveDataProvider(): array
182+
{
183+
return [
184+
[0, 'noQuoteMaskId', ''],
185+
[1, 'quoteMaskId', 'quoteMaskId']
186+
];
187+
}
137188
}

0 commit comments

Comments
 (0)