Skip to content

Commit

Permalink
Removed duplicate case & applied logic fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
yogeshsuhagiya committed Mar 26, 2019
1 parent f9ecace commit 16ce046
Showing 1 changed file with 27 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,25 @@ public function testShippingMethodWithVirtualProduct()
);

self::expectException(\Exception::class);
self::expectExceptionMessage('Carrier with such method not found: ' . $methodCode . ', ' . $methodCode . '');
self::expectExceptionMessage('You can\'t set shipping methods for virtual products');
$this->graphQlQuery($query);
}

/**
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
* @magentoApiDataFixture Magento/Sales/_files/guest_quote_with_addresses.php
*/
public function testShippingMethodWithSimpleProduct()
{
$methodCode = 'flatrate';
$carrierCode = 'flatrate';
$reservedOrderId = 'test_order_with_simple_product_without_address';
$reservedOrderId = 'guest_quote';

$maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId($reservedOrderId);
$quoteAddressId = $this->getQuoteAddressIdByReversedQuoteId($reservedOrderId);

/** @var Quote $quote */
$quote = $this->quoteFactory->create();
$this->quoteResource->load($quote, $reservedOrderId, 'reserved_order_id');
$quoteAddressId = (int) $quote->getShippingAddress()->getId();

$query = $this->prepareMutationQuery(
$maskedQuoteId,
Expand All @@ -109,27 +113,38 @@ public function testShippingMethodWithSimpleProduct()
/**
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
* @expectedException \Exception
* @expectedExceptionMessage Required parameter "cart_address_id" is missing.
*/
public function testShippingMethodWithSimpleProductWithoutAddress()
public function testShippingMethodWithSimpleProductWithoutAddress(int $addressId, string $message)
{
$methodCode = 'flatrate';
$carrierCode = 'flatrate';
$reservedOrderId = 'test_order_with_simple_product_without_address';

$maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId($reservedOrderId);
$quoteAddressId = 0;

$query = $this->prepareMutationQuery(
$maskedQuoteId,
$methodCode,
$carrierCode,
$quoteAddressId
$addressId
);

$this->expectExceptionMessage($message);
$this->graphQlQuery($query);
}

/**
* @return array
*/
public function dataProviderWithMissedRequiredParameters()
{
return [
'shipping_methods' => [
0,
'Required parameter "cart_address_id" is missing.',
]
];
}

/**
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
* @expectedException \Exception
Expand Down Expand Up @@ -213,16 +228,15 @@ public function testSetShippingMethodIfAddressIsNotBelongToCart()

/**
* @magentoApiDataFixture Magento/Sales/_files/guest_quote_with_addresses.php
* @expectedException \Magento\Framework\Exception\NoSuchEntityException
* @expectedExceptionMessage No such entity with cartId = 0
* @expectedException \Magento\TestFramework\TestCase\GraphQl\ResponseContainsErrorsException
* @expectedExceptionMessage Could not find a cart with ID "non_existent_masked_id"
*/
public function testSetShippingMethodToNonExistentCart()
{
$methodCode = 'flatrate';
$carrierCode = 'flatrate';
$reservedOrderId = 'non_existent_cart_reversed_quote_id';

$maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId($reservedOrderId);
$maskedQuoteId = 'non_existent_masked_id';
$quoteAddressId = 1;

$query = $this->prepareMutationQuery(
Expand All @@ -235,41 +249,6 @@ public function testSetShippingMethodToNonExistentCart()
$this->graphQlQuery($query);
}

/**
* @magentoApiDataFixture Magento/Sales/_files/guest_quote_with_addresses.php
*/
public function testSetShippingMethodToGuestCart()
{
$methodCode = 'flatrate';
$carrierCode = 'flatrate';
$reservedOrderId = 'guest_quote';

$maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId($reservedOrderId);

/** @var Quote $quote */
$quote = $this->quoteFactory->create();
$this->quoteResource->load($quote, $reservedOrderId, 'reserved_order_id');
$quoteAddressId = (int) $quote->getShippingAddress()->getId();

$query = $this->prepareMutationQuery(
$maskedQuoteId,
$methodCode,
$carrierCode,
$quoteAddressId
);

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

self::assertArrayHasKey('setShippingMethodsOnCart', $response);
self::assertArrayHasKey('cart', $response['setShippingMethodsOnCart']);
self::assertArrayHasKey('shipping_addresses', $response['setShippingMethodsOnCart']['cart']);

$shippingMethod = current($response['setShippingMethodsOnCart']['cart']['shipping_addresses']);
self::assertArrayHasKey('selected_shipping_method', $shippingMethod);
self::assertEquals($carrierCode, $shippingMethod['selected_shipping_method']['carrier_code']);
self::assertEquals($methodCode, $shippingMethod['selected_shipping_method']['method_code']);
}

/**
* @magentoApiDataFixture Magento/Sales/_files/guest_quote_with_addresses.php
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_virtual_product_and_address.php
Expand Down

0 comments on commit 16ce046

Please sign in to comment.