Skip to content

Commit def6657

Browse files
committed
Add test reproducing magento#658
1 parent 6e534ad commit def6657

File tree

1 file changed

+145
-1
lines changed

1 file changed

+145
-1
lines changed

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetShippingMethodsOnCartTest.php

Lines changed: 145 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,31 @@ public function testSetShippingMethodWithWrongParameters(string $input, string $
185185
$this->graphQlMutation($query);
186186
}
187187

188+
/**
189+
* Test region code returns as expected following a failure to set shipping methods
190+
*
191+
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
192+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
193+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
194+
* @throws Exception
195+
*/
196+
public function testShippingRegionOnMethodSetError()
197+
{
198+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
199+
200+
$setAddressesResult = $this->graphQlMutation($this->getSetShippingAddressWithLowerCaseCountryOnCartMutation($maskedQuoteId));
201+
$setAddresses = $setAddressesResult['setShippingAddressesOnCart']['cart']['shipping_addresses'];
202+
203+
$this->expectException(\Exception::class);
204+
try {
205+
$this->graphQlMutation($this->getInvalidSetShippingMethodMutation($maskedQuoteId));
206+
} catch (\Exception $e) {
207+
$currentShippingAddresses = $this->queryShippingAddresses($maskedQuoteId);
208+
$this->assertEquals($setAddresses[0]['region']['code'], $currentShippingAddresses[0]['region']['code']);
209+
throw $e;
210+
}
211+
}
212+
188213
/**
189214
* @return array
190215
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
@@ -331,7 +356,7 @@ public function testSetShippingMethodToCustomerCart()
331356
);
332357
$this->graphQlMutation($query);
333358
}
334-
359+
335360
/**
336361
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
337362
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
@@ -397,4 +422,123 @@ private function getQuery(
397422
}
398423
QUERY;
399424
}
425+
426+
/**
427+
* Get mutation setting shipping address on cart with lowercase country code
428+
*
429+
* @param string $maskedQuoteId
430+
* @return string
431+
*/
432+
private function getSetShippingAddressWithLowerCaseCountryOnCartMutation(string $maskedQuoteId): string
433+
{
434+
return <<<QUERY
435+
mutation {
436+
setShippingAddressesOnCart(
437+
input: {
438+
cart_id: "{$maskedQuoteId}"
439+
shipping_addresses: [
440+
{
441+
address: {
442+
firstname: "John"
443+
lastname: "Doe"
444+
street: ["6161 West Centinella Avenue"]
445+
city: "Culver City"
446+
region: "CA"
447+
postcode: "90230"
448+
country_code: "us"
449+
telephone: "555-555-55-55"
450+
save_in_address_book: false
451+
}
452+
}
453+
]
454+
}
455+
) {
456+
cart {
457+
shipping_addresses {
458+
firstname
459+
lastname
460+
city
461+
postcode
462+
region {
463+
label
464+
code
465+
}
466+
selected_shipping_method {
467+
carrier_code
468+
method_code
469+
}
470+
available_shipping_methods {
471+
carrier_code
472+
method_code
473+
carrier_title
474+
method_title
475+
}
476+
}
477+
}
478+
}
479+
}
480+
QUERY;
481+
}
482+
483+
/**
484+
* Get mutation setting invalid shipping method on cart
485+
*
486+
* @param string $maskedQuoteId
487+
* @return string
488+
*/
489+
private function getInvalidSetShippingMethodMutation(string $maskedQuoteId): string
490+
{
491+
return <<<QUERY
492+
mutation {
493+
setShippingMethodsOnCart(input: {
494+
cart_id: "{$maskedQuoteId}",
495+
shipping_methods: [{
496+
carrier_code: "flatrate"
497+
method_code: "wrong-carrier-code"
498+
}]
499+
}) {
500+
cart {
501+
shipping_addresses {
502+
selected_shipping_method {
503+
carrier_code
504+
}
505+
}
506+
}
507+
}
508+
}
509+
QUERY;
510+
}
511+
512+
/**
513+
* Get current shipping addresses for a given masked quote id
514+
*
515+
* @param string $maskedQuoteId
516+
* @return array
517+
* @throws Exception
518+
*/
519+
private function queryShippingAddresses(string $maskedQuoteId): array
520+
{
521+
$query = <<<QUERY
522+
{
523+
cart(cart_id:"{$maskedQuoteId}") {
524+
shipping_addresses {
525+
street
526+
city
527+
postcode
528+
region {
529+
label
530+
code
531+
}
532+
country {
533+
code
534+
label
535+
}
536+
}
537+
}
538+
}
539+
QUERY;
540+
541+
$result = $this->graphQlQuery($query);
542+
return $result['cart']['shipping_addresses'] ?? [];
543+
}
400544
}

0 commit comments

Comments
 (0)