This repository was archived by the owner on Dec 19, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 153
428 - Test coverage: GetAvailableShippingMethodsTest #472
Merged
magento-engcom-team
merged 13 commits into
2.3-develop
from
428-getAvailableShippingMethodsTest
Mar 30, 2019
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
36a5981
428 - Test coverage: GetAvailableShippingMethodsTest
atwixfirster 10a2202
428 - Test coverage: GetAvailableShippingMethodsTest
atwixfirster 4ed4d59
428 - Test coverage: GetAvailableShippingMethodsTest
atwixfirster 89a8621
428 - Test coverage: GetAvailableShippingMethodsTest
atwixfirster d2a7142
428 - Test coverage: GetAvailableShippingMethodsTest
atwixfirster c0b8e3d
Merge remote-tracking branch 'origin/2.3-develop' into 428-getAvailab…
naydav 99134c0
GraphQL-428: Test coverage: GetAvailableShippingMethodsTest
naydav 8136c38
428 - Test coverage: GetAvailableShippingMethodsTest
atwixfirster 0b8bebc
GraphQL-428: Test coverage: GetAvailableShippingMethodsTest
naydav 38dd5a0
428 - Test coverage: GetAvailableShippingMethodsTest
atwixfirster 18e41ba
428 - Test coverage: GetAvailableShippingMethodsTest
atwixfirster d4c2b89
Merge remote-tracking branch 'origin/2.3-develop' into 428-getAvailab…
naydav b64170a
GraphQL-428: Test coverage: GetAvailableShippingMethodsTest
naydav File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
188 changes: 188 additions & 0 deletions
188
...i-functional/testsuite/Magento/GraphQl/Quote/Customer/GetAvailableShippingMethodsTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,188 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types = 1); | ||
|
||
namespace Magento\GraphQl\Quote\Customer; | ||
|
||
use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId; | ||
use Magento\Integration\Api\CustomerTokenServiceInterface; | ||
use Magento\TestFramework\Helper\Bootstrap; | ||
use Magento\TestFramework\TestCase\GraphQlAbstract; | ||
|
||
/** | ||
* Test for get available shipping methods | ||
*/ | ||
class GetAvailableShippingMethodsTest extends GraphQlAbstract | ||
{ | ||
/** | ||
* @var CustomerTokenServiceInterface | ||
*/ | ||
private $customerTokenService; | ||
|
||
/** | ||
* @var GetMaskedQuoteIdByReservedOrderId | ||
*/ | ||
private $getMaskedQuoteIdByReservedOrderId; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function setUp() | ||
{ | ||
$objectManager = Bootstrap::getObjectManager(); | ||
$this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class); | ||
$this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class); | ||
} | ||
|
||
/** | ||
* Test case: get available shipping methods from current customer quote | ||
* | ||
* @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 | ||
*/ | ||
public function testGetAvailableShippingMethods() | ||
{ | ||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); | ||
$response = $this->graphQlQuery($this->getQuery($maskedQuoteId), [], '', $this->getHeaderMap()); | ||
|
||
self::assertArrayHasKey('cart', $response); | ||
self::assertArrayHasKey('shipping_addresses', $response['cart']); | ||
self::assertCount(1, $response['cart']['shipping_addresses']); | ||
self::assertArrayHasKey('available_shipping_methods', $response['cart']['shipping_addresses'][0]); | ||
self::assertCount(1, $response['cart']['shipping_addresses'][0]['available_shipping_methods']); | ||
|
||
$expectedAddressData = [ | ||
'amount' => 10, | ||
'base_amount' => 10, | ||
'carrier_code' => 'flatrate', | ||
'carrier_title' => 'Flat Rate', | ||
'error_message' => '', | ||
'method_code' => 'flatrate', | ||
'method_title' => 'Fixed', | ||
'price_incl_tax' => 10, | ||
'price_excl_tax' => 10, | ||
]; | ||
self::assertEquals( | ||
$expectedAddressData, | ||
$response['cart']['shipping_addresses'][0]['available_shipping_methods'][0] | ||
); | ||
} | ||
|
||
/** | ||
* _security | ||
* @magentoApiDataFixture Magento/Customer/_files/customer.php | ||
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php | ||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php | ||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php | ||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php | ||
*/ | ||
public function testGetAvailableShippingMethodsFromGuestCart() | ||
{ | ||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); | ||
$query = $this->getQuery($maskedQuoteId); | ||
|
||
$this->expectExceptionMessage( | ||
"The current user cannot perform operations on cart \"$maskedQuoteId\"" | ||
); | ||
$this->graphQlQuery($query, [], '', $this->getHeaderMap()); | ||
} | ||
|
||
/** | ||
* Test case: get available shipping methods from quote of another customer | ||
* | ||
* _security | ||
* @magentoApiDataFixture Magento/Customer/_files/three_customers.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 | ||
*/ | ||
public function testGetAvailableShippingMethodsFromAnotherCustomerCart() | ||
{ | ||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); | ||
$query = $this->getQuery($maskedQuoteId); | ||
|
||
$this->expectExceptionMessage( | ||
"The current user cannot perform operations on cart \"$maskedQuoteId\"" | ||
); | ||
$this->graphQlQuery($query, [], '', $this->getHeaderMap('[email protected]')); | ||
} | ||
|
||
/** | ||
* Test case: get available shipping methods when all shipping methods are disabled | ||
* | ||
* @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/GraphQl/Quote/_files/disable_offline_shipping_methods.php | ||
*/ | ||
public function testGetAvailableShippingMethodsIfShippingMethodsAreNotPresent() | ||
{ | ||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); | ||
$response = $this->graphQlQuery($this->getQuery($maskedQuoteId), [], '', $this->getHeaderMap()); | ||
|
||
self::assertEmpty($response['cart']['shipping_addresses'][0]['available_shipping_methods']); | ||
} | ||
|
||
/** | ||
* Test case: get available shipping methods from non-existent cart | ||
* | ||
* @magentoApiDataFixture Magento/Customer/_files/customer.php | ||
* @expectedException \Exception | ||
* @expectedExceptionMessage Could not find a cart with ID "non_existent_masked_id" | ||
*/ | ||
public function testGetAvailableShippingMethodsOfNonExistentCart() | ||
{ | ||
$maskedQuoteId = 'non_existent_masked_id'; | ||
$query = $this->getQuery($maskedQuoteId); | ||
|
||
$this->graphQlQuery($query, [], '', $this->getHeaderMap()); | ||
} | ||
|
||
/** | ||
* @param string $maskedQuoteId | ||
* @return string | ||
*/ | ||
private function getQuery(string $maskedQuoteId): string | ||
{ | ||
return <<<QUERY | ||
query { | ||
cart (cart_id: "{$maskedQuoteId}") { | ||
shipping_addresses { | ||
available_shipping_methods { | ||
amount | ||
base_amount | ||
carrier_code | ||
carrier_title | ||
error_message | ||
method_code | ||
method_title | ||
price_excl_tax | ||
price_incl_tax | ||
} | ||
} | ||
} | ||
} | ||
QUERY; | ||
} | ||
|
||
/** | ||
* @param string $username | ||
* @param string $password | ||
* @return array | ||
*/ | ||
private function getHeaderMap(string $username = '[email protected]', string $password = 'password'): array | ||
{ | ||
$customerToken = $this->customerTokenService->createCustomerAccessToken($username, $password); | ||
$headerMap = ['Authorization' => 'Bearer ' . $customerToken]; | ||
return $headerMap; | ||
} | ||
} |
121 changes: 0 additions & 121 deletions
121
dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/GetAvailableShippingMethodsTest.php
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, check scheme
Looks like we don't have these fields in scheme declaration
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@naydav , could you please check
app/code/Magento/QuoteGraphQl/etc/schema.graphqls, lines
197-206.