Skip to content

Commit

Permalink
magento/graphql-ce#540: Replace deprecated Magento/Checkout/_files/qu…
Browse files Browse the repository at this point in the history
…ote_with_address_saved.php fixture in SetUpsShippingMethodsOnCartTest
  • Loading branch information
atwixfirster committed Apr 2, 2019
1 parent ba6c523 commit 844fc58
Showing 1 changed file with 122 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId;
use Magento\GraphQl\Quote\GetQuoteShippingAddressIdByReservedQuoteId;
use Magento\Integration\Api\CustomerTokenServiceInterface;
use Magento\Quote\Model\ResourceModel\Quote as QuoteResource;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\TestCase\GraphQlAbstract;

Expand All @@ -20,19 +19,14 @@
class SetUpsShippingMethodsOnCartTest extends GraphQlAbstract
{
/**
* Defines carrier code for "UPS" shipping method
*/
const CARRIER_CODE = 'ups';

/**
* Defines method code for the "Ground" UPS shipping
* Defines carrier label for "UPS" shipping method
*/
const CARRIER_METHOD_CODE_GROUND = 'GND';
const CARRIER_LABEL = 'United Parcel Service';

/**
* @var GetQuoteShippingAddressIdByReservedQuoteId
* Defines carrier code for "UPS" shipping method
*/
private $getQuoteShippingAddressIdByReservedQuoteId;
const CARRIER_CODE = 'ups';

/**
* @var CustomerTokenServiceInterface
Expand All @@ -44,6 +38,11 @@ class SetUpsShippingMethodsOnCartTest extends GraphQlAbstract
*/
private $getMaskedQuoteIdByReservedOrderId;

/**
* @var GetQuoteShippingAddressIdByReservedQuoteId
*/
private $getQuoteShippingAddressIdByReservedQuoteId;

/**
* @inheritdoc
*/
Expand All @@ -57,13 +56,17 @@ protected function setUp()

/**
* @magentoApiDataFixture Magento/Customer/_files/customer.php
* @magentoApiDataFixture Magento/Catalog/_files/products.php
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
* @magentoApiDataFixture Magento/Ups/_files/enable_ups_shipping_method.php
*
* @param string $carrierMethodCode
* @param string $carrierMethodLabel
* @dataProvider availableForCartShippingMethods
*/
public function testSetUpsShippingMethod()
public function testSetAvailableForCartUpsShippingMethod(string $carrierMethodCode, string $carrierMethodLabel)
{
$quoteReservedId = 'test_quote';
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($quoteReservedId);
Expand All @@ -73,19 +76,123 @@ public function testSetUpsShippingMethod()
$maskedQuoteId,
$shippingAddressId,
self::CARRIER_CODE,
self::CARRIER_METHOD_CODE_GROUND
$carrierMethodCode
);

$response = $this->sendRequestWithToken($query);

$addressesInformation = $response['setShippingMethodsOnCart']['cart']['shipping_addresses'];
$expectedResult = [
'carrier_code' => self::CARRIER_CODE,
'method_code' => self::CARRIER_METHOD_CODE_GROUND,
'label' => 'United Parcel Service - Ground',
'method_code' => $carrierMethodCode,
'label' => self::CARRIER_LABEL . ' - ' . $carrierMethodLabel,
];
self::assertEquals($addressesInformation[0]['selected_shipping_method'], $expectedResult);
}

/**
* @magentoApiDataFixture Magento/Customer/_files/customer.php
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
* @magentoApiDataFixture Magento/Ups/_files/enable_ups_shipping_method.php
*
* @param string $carrierMethodCode
* @param string $carrierMethodLabel
* @dataProvider notAvailableForCartShippingMethods
*/
public function testSetNotAvailableForCartUpsShippingMethod(string $carrierMethodCode, string $carrierMethodLabel)
{
$quoteReservedId = 'test_quote';
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($quoteReservedId);
$shippingAddressId = $this->getQuoteShippingAddressIdByReservedQuoteId->execute($quoteReservedId);

$query = $this->getQuery(
$maskedQuoteId,
$shippingAddressId,
self::CARRIER_CODE,
$carrierMethodCode
);

$this->expectExceptionMessage(
"GraphQL response contains errors: Carrier with such method not found: " . self::CARRIER_CODE . ", " . $carrierMethodCode
);

$response = $this->sendRequestWithToken($query);

$addressesInformation = $response['setShippingMethodsOnCart']['cart']['shipping_addresses'];
$expectedResult = [
'carrier_code' => self::CARRIER_CODE,
'method_code' => $carrierMethodCode,
'label' => self::CARRIER_LABEL . ' - ' . $carrierMethodLabel,
];
self::assertEquals($addressesInformation[0]['selected_shipping_method'], $expectedResult);
}

/**
* @return array
*/
public function availableForCartShippingMethods(): array
{
$shippingMethods = ['1DM', '1DA', '2DA', '3DS', 'GND'];

return $this->filterShippingMethodsByCodes($shippingMethods);
}

/**
* @return array
*/
public function notAvailableForCartShippingMethods(): array
{
$shippingMethods = ['1DML', '1DAL', '1DAPI', '1DP', '1DPL', '2DM', '2DML', '2DAL', 'GNDCOM', 'GNDRES', 'STD', 'XPR', 'WXS', 'XPRL', 'XDM', 'XDML', 'XPD'];

return $this->filterShippingMethodsByCodes($shippingMethods);
}

/**
* @param array $filter
* @return array
*/
private function filterShippingMethodsByCodes(array $filter):array
{
$result = [];
foreach ($this->getAllUpsShippingMethods() as $shippingMethod) {
if (in_array($shippingMethod[0], $filter)) {
$result[] = $shippingMethod;
}
}
return $result;
}

private function getAllUpsShippingMethods():array
{
return [
['1DM', 'Next Day Air Early AM'],
['1DML', 'Next Day Air Early AM Letter'],
['1DA', 'Next Day Air'],
['1DAL', 'Next Day Air Letter'],
['1DAPI', 'Next Day Air Intra (Puerto Rico)'],
['1DP', 'Next Day Air Saver'],
['1DPL', 'Next Day Air Saver Letter'],
['2DM', '2nd Day Air AM'],
['2DML', '2nd Day Air AM Letter'],
['2DA', '2nd Day Air'],
['2DAL', '2nd Day Air Letter'],
['3DS', '3 Day Select'],
['GND', 'Ground'],
['GNDCOM', 'Ground Commercial'],
['GNDRES', 'Ground Residential'],
['STD', 'Canada Standard'],
['XPR', 'Worldwide Express'],
['WXS', 'Worldwide Express Saver'],
['XPRL', 'Worldwide Express Letter'],
['XDM', 'Worldwide Express Plus'],
['XDML', 'Worldwide Express Plus Letter'],
['XPD', 'Worldwide Expedited'],
];
}

/**
* Generates query for setting the specified shipping method on cart
*
Expand Down

0 comments on commit 844fc58

Please sign in to comment.