Skip to content

Commit

Permalink
GraphQL-428: Test coverage: GetAvailableShippingMethodsTest
Browse files Browse the repository at this point in the history
  • Loading branch information
naydav committed Mar 25, 2019
1 parent c0b8e3d commit 99134c0
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ protected function setUp()
/**
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_items_saved.php
*/
public function testGetCartWithPaymentMethods()
public function testGetAvailablePaymentMethods()
{
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('test_order_item_with_items');
$query = $this->getQuery($maskedQuoteId);
Expand All @@ -74,7 +74,7 @@ public function testGetCartWithPaymentMethods()
* @magentoApiDataFixture Magento/Customer/_files/customer.php
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_virtual_product_saved.php
*/
public function testGetPaymentMethodsFromGuestCart()
public function testGetAvailablePaymentMethodsFromGuestCart()
{
$guestQuoteMaskedId = $this->getMaskedQuoteIdByReservedOrderId(
'test_order_with_virtual_product_without_address'
Expand All @@ -91,7 +91,7 @@ public function testGetPaymentMethodsFromGuestCart()
* @magentoApiDataFixture Magento/Customer/_files/three_customers.php
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_items_saved.php
*/
public function testGetPaymentMethodsFromAnotherCustomerCart()
public function testGetAvailablePaymentMethodsFromAnotherCustomerCart()
{
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('test_order_item_with_items');
$query = $this->getQuery($maskedQuoteId);
Expand All @@ -106,7 +106,7 @@ public function testGetPaymentMethodsFromAnotherCustomerCart()
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_items_saved.php
* @magentoApiDataFixture Magento/Payment/_files/disable_all_active_payment_methods.php
*/
public function testGetPaymentMethodsIfPaymentsAreNotSet()
public function testGetAvailablePaymentMethodsIfAllPaymentsAreDisabled()
{
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('test_order_item_with_items');
$query = $this->getQuery($maskedQuoteId);
Expand All @@ -120,7 +120,7 @@ public function testGetPaymentMethodsIfPaymentsAreNotSet()
* @expectedException \Exception
* @expectedExceptionMessage Could not find a cart with ID "non_existent_masked_id"
*/
public function testGetPaymentMethodsOfNonExistentCart()
public function testGetAvailablePaymentMethodsOfNonExistentCart()
{
$maskedQuoteId = 'non_existent_masked_id';
$query = $this->getQuery($maskedQuoteId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ protected function setUp()
{
$objectManager = Bootstrap::getObjectManager();
$this->quoteFactory = $objectManager->get(QuoteFactory::class);
$this->quoteResource = $objectManager->create(QuoteResource::class);
$this->quoteResource = $objectManager->get(QuoteResource::class);
$this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class);
$this->quoteIdToMaskedId = $objectManager->create(QuoteIdToMaskedQuoteIdInterface::class);
$this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class);
}

/**
Expand All @@ -59,7 +59,7 @@ protected function setUp()
public function testGetAvailableShippingMethods()
{
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('test_order_1');
$response = $this->graphQlQuery($this->getAvailableShippingMethodsQuery($maskedQuoteId), [], '', $this->getHeaderMap());
$response = $this->graphQlQuery($this->getQuery($maskedQuoteId), [], '', $this->getHeaderMap());

self::assertArrayHasKey('cart', $response);
self::assertArrayHasKey('shipping_addresses', $response['cart']);
Expand Down Expand Up @@ -98,7 +98,12 @@ public function testGetAvailableShippingMethodsFromAnotherCustomerCart()
"The current user cannot perform operations on cart \"$maskedQuoteId\""
);

$this->graphQlQuery($this->getAvailableShippingMethodsQuery($maskedQuoteId), [], '', $this->getHeaderMap('customer2@search.example.com'));
$this->graphQlQuery(
$this->getQuery($maskedQuoteId),
[],
'',
$this->getHeaderMap('customer2@search.example.com')
);
}

/**
Expand All @@ -107,10 +112,10 @@ public function testGetAvailableShippingMethodsFromAnotherCustomerCart()
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php
* @magentoApiDataFixture Magento/OfflineShipping/_files/disable_offline_shipping_methods.php
*/
public function testGetAvailableShippingMethodsIfShippingsAreNotSet()
public function testGetAvailableShippingMethodsIfAllShippingsAreDisabled()
{
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('test_order_1');
$response = $this->graphQlQuery($this->getAvailableShippingMethodsQuery($maskedQuoteId), [], '', $this->getHeaderMap());
$response = $this->graphQlQuery($this->getQuery($maskedQuoteId), [], '', $this->getHeaderMap());

self::assertEquals(0, count($response['cart']['shipping_addresses'][0]['available_shipping_methods']));
}
Expand All @@ -125,7 +130,7 @@ public function testGetAvailableShippingMethodsIfShippingsAreNotSet()
public function testGetAvailableShippingMethodsOfNonExistentCart()
{
$maskedQuoteId = 'non_existent_masked_id';
$query = $this->getAvailableShippingMethodsQuery($maskedQuoteId);
$query = $this->getQuery($maskedQuoteId);

$this->graphQlQuery($query, [], '', $this->getHeaderMap());
}
Expand All @@ -134,7 +139,7 @@ public function testGetAvailableShippingMethodsOfNonExistentCart()
* @param string $maskedQuoteId
* @return string
*/
private function getAvailableShippingMethodsQuery(
private function getQuery(
string $maskedQuoteId
): string
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected function setUp()
/**
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
*/
public function testGetCartWithPaymentMethods()
public function testGetAvailablePaymentMethods()
{
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('test_order_with_simple_product_without_address');
$query = $this->getQuery($maskedQuoteId);
Expand All @@ -73,7 +73,7 @@ public function testGetCartWithPaymentMethods()
/**
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php
*/
public function testGetPaymentMethodsFromCustomerCart()
public function testGetAvailablePaymentMethodsFromCustomerCart()
{
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('test_order_1');
$query = $this->getQuery($maskedQuoteId);
Expand All @@ -88,7 +88,7 @@ public function testGetPaymentMethodsFromCustomerCart()
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
* @magentoApiDataFixture Magento/Payment/_files/disable_all_active_payment_methods.php
*/
public function testGetPaymentMethodsIfPaymentsAreNotSet()
public function testGetPaymentMethodsIfPaymentsAreDisabled()
{
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('test_order_with_simple_product_without_address');
$query = $this->getQuery($maskedQuoteId);
Expand All @@ -101,7 +101,7 @@ public function testGetPaymentMethodsIfPaymentsAreNotSet()
* @expectedException \Exception
* @expectedExceptionMessage Could not find a cart with ID "non_existent_masked_id"
*/
public function testGetPaymentMethodsOfNonExistentCart()
public function testGetAvailablePaymentMethodsOfNonExistentCart()
{
$maskedQuoteId = 'non_existent_masked_id';
$query = $this->getQuery($maskedQuoteId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,19 @@ protected function setUp()
{
$objectManager = Bootstrap::getObjectManager();
$this->quoteFactory = $objectManager->get(QuoteFactory::class);
$this->quoteResource = $objectManager->create(QuoteResource::class);
$this->quoteIdToMaskedId = $objectManager->create(QuoteIdToMaskedQuoteIdInterface::class);
$this->quoteResource = $objectManager->get(QuoteResource::class);
$this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class);
}

/**
* Test case: get available shipping methods from current customer quote
*
* @magentoApiDataFixture Magento/Sales/_files/guest_quote_with_addresses.php
*/
public function testGetAvailableShippingMethodsFromGuestCart()
public function testGetAvailableShippingMethods()
{
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('guest_quote');
$response = $this->graphQlQuery($this->getAvailableShippingMethodsQuery($maskedQuoteId));
$response = $this->graphQlQuery($this->getQuery($maskedQuoteId));

self::assertArrayHasKey('cart', $response);
self::assertArrayHasKey('shipping_addresses', $response['cart']);
Expand Down Expand Up @@ -82,15 +82,15 @@ public function testGetAvailableShippingMethodsFromGuestCart()
*
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php
*/
public function testGetAvailableShippingMethodsFromAnotherCustomerCart()
public function testGetAvailableShippingMethodsFromCustomerCart()
{
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('test_order_1');

$this->expectExceptionMessage(
"The current user cannot perform operations on cart \"$maskedQuoteId\""
);

$this->graphQlQuery($this->getAvailableShippingMethodsQuery($maskedQuoteId));
$this->graphQlQuery($this->getQuery($maskedQuoteId));
}

/**
Expand All @@ -99,10 +99,10 @@ public function testGetAvailableShippingMethodsFromAnotherCustomerCart()
* @magentoApiDataFixture Magento/Sales/_files/guest_quote_with_addresses.php
* @magentoApiDataFixture Magento/OfflineShipping/_files/disable_offline_shipping_methods.php
*/
public function testGetAvailableShippingMethodsIfShippingsAreNotSet()
public function testGetAvailableShippingMethodsIfShippingsAreDisabled()
{
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('guest_quote');
$response = $this->graphQlQuery($this->getAvailableShippingMethodsQuery($maskedQuoteId));
$response = $this->graphQlQuery($this->getQuery($maskedQuoteId));

self::assertEquals(0, count($response['cart']['shipping_addresses'][0]['available_shipping_methods']));
}
Expand All @@ -117,14 +117,14 @@ public function testGetAvailableShippingMethodsOfNonExistentCart()
{
$maskedQuoteId = 'non_existent_masked_id';

$this->graphQlQuery($this->getAvailableShippingMethodsQuery($maskedQuoteId));
$this->graphQlQuery($this->getQuery($maskedQuoteId));
}

/**
* @param string $maskedQuoteId
* @return string
*/
private function getAvailableShippingMethodsQuery(
private function getQuery(
string $maskedQuoteId
): string
{
Expand Down

0 comments on commit 99134c0

Please sign in to comment.