-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
graphQl-427: adjusted code coverage of set shipping address feature
- Loading branch information
Vitaliy Boyko
committed
Mar 6, 2019
1 parent
75cf826
commit e1d5544
Showing
2 changed files
with
496 additions
and
141 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -5,17 +5,14 @@ | |
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\GraphQl\Quote; | ||
namespace Magento\GraphQl\Quote\Customer; | ||
|
||
use Magento\Framework\App\Config\ScopeConfigInterface; | ||
use Magento\Integration\Api\CustomerTokenServiceInterface; | ||
use Magento\Multishipping\Helper\Data; | ||
use Magento\Quote\Model\QuoteFactory; | ||
use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface; | ||
use Magento\Quote\Model\ResourceModel\Quote as QuoteResource; | ||
use Magento\TestFramework\Helper\Bootstrap; | ||
use Magento\TestFramework\TestCase\GraphQlAbstract; | ||
use Magento\TestFramework\ObjectManager; | ||
|
||
/** | ||
* Test for set shipping addresses on cart mutation | ||
|
@@ -53,10 +50,11 @@ protected function setUp() | |
|
||
/** | ||
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php | ||
* @magentoApiDataFixture Magento/Customer/_files/customer.php | ||
*/ | ||
public function testSetNewShippingAddressByGuest() | ||
public function testSetNewShippingAddress() | ||
{ | ||
$maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_with_simple_product_without_address'); | ||
$maskedQuoteId = $this->assignQuoteToCustomer(); | ||
|
||
$query = <<<QUERY | ||
mutation { | ||
|
@@ -91,16 +89,16 @@ public function testSetNewShippingAddressByGuest() | |
postcode | ||
telephone | ||
country { | ||
code | ||
label | ||
code | ||
} | ||
address_type | ||
} | ||
} | ||
} | ||
} | ||
QUERY; | ||
$response = $this->graphQlQuery($query); | ||
$response = $this->graphQlQuery($query, [], '', $this->getHeaderMap()); | ||
|
||
self::assertArrayHasKey('cart', $response['setShippingAddressesOnCart']); | ||
$cartResponse = $response['setShippingAddressesOnCart']['cart']; | ||
|
@@ -111,12 +109,15 @@ public function testSetNewShippingAddressByGuest() | |
|
||
/** | ||
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php | ||
* @expectedException \Exception | ||
* @expectedExceptionMessage The current customer isn't authorized. | ||
* @magentoApiDataFixture Magento/Customer/_files/customer.php | ||
* @dataProvider requestWithoutRequiredParamsDataProvider | ||
* @param string $params | ||
* @param string $expectedException | ||
* @throws \Exception | ||
*/ | ||
public function testSetShippingAddressFromAddressBookByGuest() | ||
public function testSetNewShippingAddressWithEmptyRequiredParams(string $params, string $expectedException) | ||
{ | ||
$maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_with_simple_product_without_address'); | ||
$maskedQuoteId = $this->assignQuoteToCustomer(); | ||
|
||
$query = <<<QUERY | ||
mutation { | ||
|
@@ -125,7 +126,9 @@ public function testSetShippingAddressFromAddressBookByGuest() | |
cart_id: "$maskedQuoteId" | ||
shipping_addresses: [ | ||
{ | ||
customer_address_id: 1 | ||
address: { | ||
$params | ||
} | ||
} | ||
] | ||
} | ||
|
@@ -138,16 +141,21 @@ public function testSetShippingAddressFromAddressBookByGuest() | |
} | ||
} | ||
QUERY; | ||
$this->graphQlQuery($query); | ||
$this->expectExceptionMessage( | ||
$expectedException | ||
); | ||
$this->graphQlQuery($query, [], '', $this->getHeaderMap()); | ||
} | ||
|
||
/** | ||
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php | ||
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_virtual_product_saved.php | ||
* @magentoApiDataFixture Magento/Customer/_files/customer.php | ||
* @expectedException \Exception | ||
* @expectedExceptionMessage The Cart includes virtual product(s) only, so a shipping address is not used. | ||
*/ | ||
public function testSetNewShippingAddressByRegisteredCustomer() | ||
public function testSetNewShippingAddressOnQuoteWithVirtualProducts() | ||
{ | ||
$maskedQuoteId = $this->assignQuoteToCustomer(); | ||
$maskedQuoteId = $this->assignQuoteToCustomer('test_order_with_virtual_product_without_address'); | ||
|
||
$query = <<<QUERY | ||
mutation { | ||
|
@@ -174,38 +182,21 @@ public function testSetNewShippingAddressByRegisteredCustomer() | |
) { | ||
cart { | ||
shipping_addresses { | ||
firstname | ||
lastname | ||
company | ||
street | ||
city | ||
postcode | ||
telephone | ||
country { | ||
label | ||
code | ||
} | ||
address_type | ||
} | ||
} | ||
} | ||
} | ||
QUERY; | ||
$response = $this->graphQlQuery($query, [], '', $this->getHeaderMap()); | ||
|
||
self::assertArrayHasKey('cart', $response['setShippingAddressesOnCart']); | ||
$cartResponse = $response['setShippingAddressesOnCart']['cart']; | ||
self::assertArrayHasKey('shipping_addresses', $cartResponse); | ||
$shippingAddressResponse = current($cartResponse['shipping_addresses']); | ||
$this->assertNewShippingAddressFields($shippingAddressResponse); | ||
$this->graphQlQuery($query, [], '', $this->getHeaderMap()); | ||
} | ||
|
||
/** | ||
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php | ||
* @magentoApiDataFixture Magento/Customer/_files/customer.php | ||
* @magentoApiDataFixture Magento/Customer/_files/customer_two_addresses.php | ||
*/ | ||
public function testSetShippingAddressFromAddressBookByRegisteredCustomer() | ||
public function testSetShippingAddressFromAddressBook() | ||
{ | ||
$maskedQuoteId = $this->assignQuoteToCustomer(); | ||
|
||
|
@@ -277,36 +268,6 @@ public function testSetNotExistedShippingAddressFromAddressBook() | |
$this->graphQlQuery($query, [], '', $this->getHeaderMap()); | ||
} | ||
|
||
/** | ||
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php | ||
* @expectedException \Exception | ||
* @expectedExceptionMessage The shipping address must contain either "customer_address_id" or "address". | ||
*/ | ||
public function testSetShippingAddressWithoutAddresses() | ||
{ | ||
$maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_with_simple_product_without_address'); | ||
|
||
$query = <<<QUERY | ||
mutation { | ||
setShippingAddressesOnCart( | ||
input: { | ||
cart_id: "$maskedQuoteId" | ||
shipping_addresses: [ | ||
{} | ||
] | ||
} | ||
) { | ||
cart { | ||
shipping_addresses { | ||
city | ||
} | ||
} | ||
} | ||
} | ||
QUERY; | ||
$this->graphQlQuery($query); | ||
} | ||
|
||
/** | ||
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php | ||
* @magentoApiDataFixture Magento/Customer/_files/customer.php | ||
|
@@ -355,13 +316,15 @@ public function testSetNewShippingAddressAndFromAddressBookAtSameTime() | |
} | ||
|
||
/** | ||
* @magentoApiDataFixture Magento/Customer/_files/three_customers.php | ||
* @magentoApiDataFixture Magento/Customer/_files/customer_address.php | ||
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php | ||
* @expectedException \Exception | ||
* @expectedExceptionMessage You cannot specify multiple shipping addresses. | ||
* @expectedExceptionMessage The current user cannot use address with ID "1" | ||
*/ | ||
public function testSetMultipleNewShippingAddresses() | ||
public function testSetShippingAddressIfCustomerIsNotOwnerOfAddress() | ||
{ | ||
$maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_with_simple_product_without_address'); | ||
$maskedQuoteId = $this->assignQuoteToCustomer('test_order_with_simple_product_without_address', 2); | ||
|
||
$query = <<<QUERY | ||
mutation { | ||
|
@@ -370,69 +333,32 @@ public function testSetMultipleNewShippingAddresses() | |
cart_id: "$maskedQuoteId" | ||
shipping_addresses: [ | ||
{ | ||
address: { | ||
firstname: "test firstname" | ||
lastname: "test lastname" | ||
company: "test company" | ||
street: ["test street 1", "test street 2"] | ||
city: "test city" | ||
region: "test region" | ||
postcode: "887766" | ||
country_code: "US" | ||
telephone: "88776655" | ||
save_in_address_book: false | ||
} | ||
}, | ||
{ | ||
address: { | ||
firstname: "test firstname 2" | ||
lastname: "test lastname 2" | ||
company: "test company 2" | ||
street: ["test street 1", "test street 2"] | ||
city: "test city" | ||
region: "test region" | ||
postcode: "887766" | ||
country_code: "US" | ||
telephone: "88776655" | ||
save_in_address_book: false | ||
} | ||
customer_address_id: 1 | ||
} | ||
] | ||
} | ||
) { | ||
cart { | ||
shipping_addresses { | ||
city | ||
postcode | ||
} | ||
} | ||
} | ||
} | ||
QUERY; | ||
/** @var \Magento\Config\Model\ResourceModel\Config $config */ | ||
$config = ObjectManager::getInstance()->get(\Magento\Config\Model\ResourceModel\Config::class); | ||
$config->saveConfig( | ||
Data::XML_PATH_CHECKOUT_MULTIPLE_AVAILABLE, | ||
null, | ||
ScopeConfigInterface::SCOPE_TYPE_DEFAULT, | ||
0 | ||
); | ||
/** @var \Magento\Framework\App\Config\ReinitableConfigInterface $config */ | ||
$config = ObjectManager::getInstance()->get(\Magento\Framework\App\Config\ReinitableConfigInterface::class); | ||
$config->reinit(); | ||
|
||
$this->graphQlQuery($query); | ||
$this->graphQlQuery($query, [], '', $this->getHeaderMap('[email protected]')); | ||
} | ||
|
||
/** | ||
* @magentoApiDataFixture Magento/Customer/_files/three_customers.php | ||
* @magentoApiDataFixture Magento/Customer/_files/customer_address.php | ||
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php | ||
* @expectedException \Exception | ||
* @expectedExceptionMessage The current user cannot use address with ID "1" | ||
*/ | ||
public function testSetShippingAddressIfCustomerIsNotOwnerOfAddress() | ||
public function testSetShippingAddressIfCustomerIsNotOwnerOfCart() | ||
{ | ||
$maskedQuoteId = $this->assignQuoteToCustomer('test_order_with_simple_product_without_address', 2); | ||
$maskedQuoteId = $this->assignQuoteToCustomer('test_order_with_simple_product_without_address', 1); | ||
|
||
$query = <<<QUERY | ||
mutation { | ||
|
@@ -454,10 +380,27 @@ public function testSetShippingAddressIfCustomerIsNotOwnerOfAddress() | |
} | ||
} | ||
QUERY; | ||
$this->expectExceptionMessage( | ||
"The current user cannot perform operations on cart \"$maskedQuoteId\"" | ||
); | ||
|
||
$this->graphQlQuery($query, [], '', $this->getHeaderMap('[email protected]')); | ||
} | ||
|
||
/** | ||
* TODO: currently only the city param is required, do we need to add at least ZIP code? | ||
* @return array | ||
*/ | ||
public function requestWithoutRequiredParamsDataProvider() | ||
{ | ||
return [ | ||
[ | ||
'save_in_address_book: false', | ||
'Field CartAddressInput.city of required type String! was not provided' | ||
] | ||
]; | ||
} | ||
|
||
/** | ||
* Verify the all the whitelisted fields for a New Address Object | ||
* | ||
|
@@ -512,18 +455,6 @@ private function getHeaderMap(string $username = '[email protected]', string | |
return $headerMap; | ||
} | ||
|
||
/** | ||
* @param string $reversedQuoteId | ||
* @return string | ||
*/ | ||
private function getMaskedQuoteIdByReversedQuoteId(string $reversedQuoteId): string | ||
{ | ||
$quote = $this->quoteFactory->create(); | ||
$this->quoteResource->load($quote, $reversedQuoteId, 'reserved_order_id'); | ||
|
||
return $this->quoteIdToMaskedId->execute((int)$quote->getId()); | ||
} | ||
|
||
/** | ||
* @param string $reversedQuoteId | ||
* @param int $customerId | ||
|
@@ -539,22 +470,4 @@ private function assignQuoteToCustomer( | |
$this->quoteResource->save($quote); | ||
return $this->quoteIdToMaskedId->execute((int)$quote->getId()); | ||
} | ||
|
||
public function tearDown() | ||
{ | ||
/** @var \Magento\Config\Model\ResourceModel\Config $config */ | ||
$config = ObjectManager::getInstance()->get(\Magento\Config\Model\ResourceModel\Config::class); | ||
|
||
//default state of multishipping config | ||
$config->saveConfig( | ||
Data::XML_PATH_CHECKOUT_MULTIPLE_AVAILABLE, | ||
1, | ||
ScopeConfigInterface::SCOPE_TYPE_DEFAULT, | ||
0 | ||
); | ||
|
||
/** @var \Magento\Framework\App\Config\ReinitableConfigInterface $config */ | ||
$config = ObjectManager::getInstance()->get(\Magento\Framework\App\Config\ReinitableConfigInterface::class); | ||
$config->reinit(); | ||
} | ||
} |
Oops, something went wrong.