Skip to content

Commit cd2fc8f

Browse files
committed
ACP2E-3942: Error in mapping message to error code when placing order via GraphQL
1 parent 4dc8064 commit cd2fc8f

File tree

2 files changed

+58
-2
lines changed

2 files changed

+58
-2
lines changed

app/code/Magento/QuoteGraphQl/Model/Cart/GetCartForCheckout.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2022 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\QuoteGraphQl\Test\Unit\Model\Cart;
10+
11+
use Magento\Framework\GraphQl\Exception\GraphQlAuthorizationException;
12+
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
13+
use Magento\QuoteGraphQl\Model\Cart\GetCartForCheckout;
14+
use Magento\QuoteGraphQl\Model\Cart\GetCartForUser;
15+
use Magento\QuoteGraphQl\Model\Cart\CheckCartCheckoutAllowance;
16+
use Magento\Framework\Exception\NoSuchEntityException;
17+
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
18+
use PHPUnit\Framework\MockObject\Exception;
19+
use PHPUnit\Framework\TestCase;
20+
21+
class GetCartForCheckoutTest extends TestCase
22+
{
23+
/**
24+
* Verifies that when GetCartForUser::execute throws a NoSuchEntityException with a specific code,
25+
* GetCartForCheckout::execute rethrows it as a GraphQlNoSuchEntityException, preserving the original
26+
* exception message and code.
27+
*
28+
* @return void
29+
* @throws GraphQlNoSuchEntityException
30+
* @throws GraphQlAuthorizationException
31+
* @throws GraphQlInputException
32+
* @throws Exception
33+
*/
34+
public function testExecuteThrowsGraphQlNoSuchEntityExceptionWithOriginalCode()
35+
{
36+
$cartHash = 'test_hash';
37+
$customerId = 1;
38+
$storeId = 2;
39+
$originalCode = 1234;
40+
$originalMessage = 'Cart not found';
41+
42+
$getCartForUser = $this->createMock(GetCartForUser::class);
43+
$getCartForUser->method('execute')
44+
->willThrowException(new NoSuchEntityException(__($originalMessage), null, $originalCode));
45+
46+
$checkoutAllowance = $this->createMock(CheckCartCheckoutAllowance::class);
47+
48+
$getCartForCheckout = new GetCartForCheckout($checkoutAllowance, $getCartForUser);
49+
50+
$this->expectException(GraphQlNoSuchEntityException::class);
51+
$this->expectExceptionMessage($originalMessage);
52+
$this->expectExceptionCode($originalCode);
53+
54+
$getCartForCheckout->execute($cartHash, $customerId, $storeId);
55+
}
56+
}

0 commit comments

Comments
 (0)