Skip to content

Commit

Permalink
Merge branch 'compr_author' of https://github.com/magento-gl/magento2ce
Browse files Browse the repository at this point in the history
… into compr_author
  • Loading branch information
Indrani Sonawane authored and Indrani Sonawane committed Oct 17, 2024
2 parents 4267628 + 6472f26 commit 86c715f
Show file tree
Hide file tree
Showing 26 changed files with 222 additions and 253 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<description value="Verify if lower than stock product quantity is accepted after changing stock qty in backend"/>
<severity value="CRITICAL"/>
<testCaseId value="AC-5987"/>
<group value="mtf_migrated"/>
<group value="mtf_migrated"/>
</annotations>

<before>
Expand Down Expand Up @@ -61,14 +61,14 @@
<waitForAjaxLoad stepKey="waitForAjaxLoad1"/>

<!--Assert "The requested qty is not available"-->
<see selector="{{CheckoutCartMessageSection.errorMessage}}" userInput="The requested qty is not available" stepKey="seeTheErrorMessageDisplayed"/>
<see selector="{{CheckoutCartMessageSection.errorMessage}}" userInput="Not enough items for sale" stepKey="seeTheErrorMessageDisplayed"/>

<fillField selector="{{CheckoutCartProductSection.qty($$simpleProduct.sku$$)}}" userInput="8" stepKey="updateProductQty"/>
<click selector="{{CheckoutCartProductSection.updateShoppingCartButton}}" stepKey="clickUpdateShoppingCart"/>
<waitForAjaxLoad stepKey="waitForAjaxLoad2"/>
<waitForAjaxLoad stepKey="waitForPageLoad2"/>

<dontSee userInput="The requested qty is not available" stepKey="dontSeeTheErrorMessageDisplayed"/>
<dontSee userInput="Not enough items for sale" stepKey="dontSeeTheErrorMessageDisplayed"/>

</test>
</tests>
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<actionGroup ref="StorefrontProductPageAddSimpleProductToCartActionGroup" stepKey="addProductToCart"/>
<!-- Check that error remains -->
<actionGroup ref="StorefrontAssertProductAddToCartErrorMessageActionGroup" stepKey="assertFailure">
<argument name="message" value="The requested qty is not available"/>
<argument name="message" value="Not enough items for sale"/>
</actionGroup>
</test>
</tests>

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,17 @@
use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Query\ResolverInterface;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Magento\OrderCancellationGraphQl\Model\CancelOrderErrorCodes;

/**
* Resolver to return the description of a CancellationReason with error code
*/
class CancelOrderError implements ResolverInterface
{
/**
* @param CancelOrderErrorCodes $cancelOrderErrorCodes
* @param array $errorMessageCodesMapper
*/
public function __construct(
private readonly CancelOrderErrorCodes $cancelOrderErrorCodes
private readonly array $errorMessageCodesMapper
) {
}

Expand All @@ -50,7 +49,7 @@ public function resolve(

return [
'message' => $value['error'],
'code' => $this->cancelOrderErrorCodes->getErrorCodeFromMapper((string) $value['error']),
'code' => $this->errorMessageCodesMapper[strtolower((string) $value['error'])] ?? 'UNDEFINED',
];
}
}
11 changes: 11 additions & 0 deletions app/code/Magento/OrderCancellationGraphQl/etc/graphql/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,15 @@
</argument>
</arguments>
</type>
<type name="Magento\OrderCancellationGraphQl\Model\Resolver\CancelOrderError">
<arguments>
<argument name="errorMessageCodesMapper" xsi:type="array">
<item name="order cancellation is not enabled for requested store." xsi:type="string">ORDER_CANCELLATION_DISABLED</item>
<item name="current user is not authorized to cancel this order" xsi:type="string">UNAUTHORISED</item>
<item name="the entity that was requested doesn't exist. verify the entity and try again." xsi:type="string">ORDER_NOT_FOUND</item>
<item name="order with one or more items shipped cannot be cancelled" xsi:type="string">PARTIAL_ORDER_ITEM_SHIPPED</item>
<item name="order already closed, complete, cancelled or on hold" xsi:type="string">INVALID_ORDER_STATUS</item>
</argument>
</arguments>
</type>
</config>
3 changes: 3 additions & 0 deletions app/code/Magento/Quote/Model/Cart/AddProductsToCartError.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class AddProductsToCartError
'The fewest you may purchase is' => self::ERROR_INSUFFICIENT_STOCK,
'The most you may purchase is' => self::ERROR_INSUFFICIENT_STOCK,
'The requested qty is not available' => self::ERROR_INSUFFICIENT_STOCK,
'Not enough items for sale' => self::ERROR_INSUFFICIENT_STOCK,
'Only %s of %s available' => self::ERROR_INSUFFICIENT_STOCK,
];

/**
Expand All @@ -59,6 +61,7 @@ public function create(string $message, int $cartItemPosition = 0): Data\Error
*/
private function getErrorCode(string $message): string
{
$message = preg_replace('/\d+/', '%s', $message);
foreach (self::MESSAGE_CODES as $codeMessage => $code) {
if (false !== stripos($message, $codeMessage)) {
return $code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
*/
private function getErrorCode(string $message): string
{
$message = preg_replace('/\d+/', '%s', $message);
foreach ($this->messageCodesMapper as $key => $code) {
if (str_contains($message, $key)) {
return $code;
Expand Down
2 changes: 2 additions & 0 deletions app/code/Magento/QuoteGraphQl/etc/graphql/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@
<item name="Could not find cart item" xsi:type="string">COULD_NOT_FIND_CART_ITEM</item>
<item name="Required parameter" xsi:type="string">REQUIRED_PARAMETER_MISSING</item>
<item name="The fewest you may purchase" xsi:type="string">INVALID_PARAMETER_VALUE</item>
<item name="Not enough items for sale" xsi:type="string">INSUFFICIENT_STOCK</item>
<item name="Only %s of %s available" xsi:type="string">INSUFFICIENT_STOCK</item>
</argument>
</arguments>
</type>
Expand Down
4 changes: 3 additions & 1 deletion app/code/Magento/Sales/Model/Reorder/Reorder.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class Reorder
'The fewest you may purchase is' => self::ERROR_INSUFFICIENT_STOCK,
'The most you may purchase is' => self::ERROR_INSUFFICIENT_STOCK,
'The requested qty is not available' => self::ERROR_INSUFFICIENT_STOCK,
'Not enough items for sale' => self::ERROR_INSUFFICIENT_STOCK,
'Only %s of %s available' => self::ERROR_INSUFFICIENT_STOCK,
];

/**
Expand Down Expand Up @@ -358,7 +360,7 @@ private function addError(string $message, string $code = null): void
private function getErrorCode(string $message): string
{
$code = self::ERROR_UNDEFINED;

$message = preg_replace('/\d+/', '%s', $message);
$matchedCodes = array_filter(
self::MESSAGE_CODES,
function ($key) use ($message) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,6 @@
<argument name="productQty" value="1"/>
</actionGroup>
<!-- Check that error remains -->
<see userInput="The requested qty is not available" stepKey="assertProductErrorRemains"/>
<see userInput="Not enough items for sale" stepKey="assertProductErrorRemains"/>
</test>
</tests>
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected function setUp(): void
public function testAddProductIfQuantityIsNotAvailable()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('The requested qty. is not available');
$this->expectExceptionMessage('Not enough items for sale');

$sku = 'simple';
$quantity = 200;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function testUpdateCartItemDecimalQuantity()
$itemId = $this->getQuoteItemIdByReservedQuoteIdAndSku->execute('test_quote', 'simple_product');

$quantity = 0.5;
$query = $this->getQuery($maskedQuoteId, $itemId, $quantity);
$query = $this->getMutation($maskedQuoteId, $itemId, $quantity);
$response = $this->graphQlMutation($query);

$this->assertArrayHasKey('updateCartItems', $response);
Expand All @@ -72,15 +72,14 @@ public function testUpdateCartItemSetUnavailableQuantity()
$itemId = $this->getQuoteItemIdByReservedQuoteIdAndSku->execute('test_quote', 'simple_product');

$quantity = 100;
$query = $this->getQuery($maskedQuoteId, $itemId, $quantity);
$query = $this->getMutation($maskedQuoteId, $itemId, $quantity);
$response = $this->graphQlMutation($query);

$this->assertArrayHasKey('updateCartItems', $response);
$this->assertArrayHasKey('errors', $response['updateCartItems']);

$responseError = $response['updateCartItems']['errors'][0];
$this->assertEquals(
"The requested qty. is not available",
"Could not update the product with SKU simple_product: Not enough items for sale",
$responseError['message']
);
$this->assertEquals('INSUFFICIENT_STOCK', $responseError['code']);
Expand All @@ -92,9 +91,9 @@ public function testUpdateCartItemSetUnavailableQuantity()
* @param float $quantity
* @return string
*/
private function getQuery(string $maskedQuoteId, int $itemId, float $quantity): string
private function getMutation(string $maskedQuoteId, int $itemId, float $quantity): string
{
return <<<QUERY
return <<<MUTATION
mutation {
updateCartItems(input: {
cart_id: "{$maskedQuoteId}"
Expand All @@ -117,6 +116,6 @@ private function getQuery(string $maskedQuoteId, int $itemId, float $quantity):
}
}
}
QUERY;
MUTATION;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public function testAddProductIfQuantityIsNotAvailable(): void
$response = $this->graphQlMutation($query);

self::assertEquals(
'The requested qty is not available',
'Not enough items for sale',
$response['addProductsToCart']['user_errors'][0]['message']
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public function testAddVariationFromAnotherConfigurableProductWithDifferentSuper
public function testAddProductIfQuantityIsNotAvailable()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('The requested qty. is not available');
$this->expectExceptionMessage('Not enough items for sale');

$searchResponse = $this->graphQlQuery($this->getFetchProductQuery('configurable'));
$product = current($searchResponse['products']['items']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ public function testAttemptToCancelOrderWhenCancellationFeatureDisabled()
reason: "Sample reason"
}
){
error
errorV2 {
message
}
order {
status
}
Expand All @@ -161,7 +163,9 @@ public function testAttemptToCancelOrderWhenCancellationFeatureDisabled()
$this->assertEquals(
[
'cancelOrder' => [
'error' => 'Order cancellation is not enabled for requested store.',
'errorV2' => [
'message' => 'Order cancellation is not enabled for requested store.'
],
'order' => null
]
],
Expand Down Expand Up @@ -199,7 +203,9 @@ public function testAttemptToCancelOrderWithSomeStatuses(string $status, string
[
'cancelOrder' =>
[
'error' => 'Order already closed, complete, cancelled or on hold',
'errorV2' => [
'message' => 'Order already closed, complete, cancelled or on hold'
],
'order' => [
'status' => $expectedStatus
]
Expand Down Expand Up @@ -240,7 +246,9 @@ public function testAttemptToCancelOrderWithOfflinePaymentFullyInvoicedFullyShip
[
'cancelOrder' =>
[
'error' => 'Order already closed, complete, cancelled or on hold',
'errorV2' => [
'message' => 'Order already closed, complete, cancelled or on hold'
],
'order' => [
'status' => 'Complete'
]
Expand Down Expand Up @@ -294,7 +302,9 @@ public function testAttemptToCancelOrderWithOfflinePaymentFullyInvoicedPartially
[
'cancelOrder' =>
[
'error' => 'Order with one or more items shipped cannot be cancelled',
'errorV2' => [
'message' => 'Order with one or more items shipped cannot be cancelled'
],
'order' => [
'status' => 'Processing'
]
Expand Down Expand Up @@ -335,7 +345,9 @@ public function testAttemptToCancelOrderWithOfflinePaymentFullyInvoicedFullyRefu
[
'cancelOrder' =>
[
'error' => 'Order already closed, complete, cancelled or on hold',
'errorV2' => [
'message' => 'Order already closed, complete, cancelled or on hold'
],
'order' => [
'status' => 'Closed'
]
Expand Down Expand Up @@ -369,7 +381,7 @@ public function testCancelOrderWithOutAnyAmountPaid()
[
'cancelOrder' =>
[
'error' => null,
'errorV2' => null,
'order' => [
'status' => 'Pending'
]
Expand Down Expand Up @@ -399,7 +411,9 @@ private function getCancelOrderMutation(OrderInterface $order): string
reason: "Cancel sample reason"
}
){
error
errorV2 {
message
}
order {
status
}
Expand Down
Loading

0 comments on commit 86c715f

Please sign in to comment.