Skip to content

Commit

Permalink
GraphQL-427: Test coverage: SetShippingAddressOnCartTest
Browse files Browse the repository at this point in the history
  • Loading branch information
naydav committed Mar 13, 2019
1 parent 32366e0 commit 5f3d076
Show file tree
Hide file tree
Showing 2 changed files with 139 additions and 150 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ protected function setUp()
}

/**
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
* @magentoApiDataFixture Magento/Customer/_files/customer.php
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
*/
public function testSetNewShippingAddress()
{
Expand Down Expand Up @@ -107,46 +107,6 @@ public function testSetNewShippingAddress()
$this->assertNewShippingAddressFields($shippingAddressResponse);
}

/**
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
* @magentoApiDataFixture Magento/Customer/_files/customer.php
* @dataProvider requestWithoutRequiredParamsDataProvider
* @param string $params
* @param string $expectedException
* @throws \Exception
*/
public function testSetNewShippingAddressWithEmptyRequiredParams(string $params, string $expectedException)
{
$maskedQuoteId = $this->assignQuoteToCustomer();

$query = <<<QUERY
mutation {
setShippingAddressesOnCart(
input: {
cart_id: "$maskedQuoteId"
shipping_addresses: [
{
address: {
$params
}
}
]
}
) {
cart {
shipping_addresses {
city
}
}
}
}
QUERY;
$this->expectExceptionMessage(
$expectedException
);
$this->graphQlQuery($query, [], '', $this->getHeaderMap());
}

/**
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_virtual_product_saved.php
* @magentoApiDataFixture Magento/Customer/_files/customer.php
Expand Down Expand Up @@ -241,7 +201,7 @@ public function testSetShippingAddressFromAddressBook()
* @expectedException \Exception
* @expectedExceptionMessage Could not find a address with ID "100"
*/
public function testSetNotExistedShippingAddressFromAddressBook()
public function testSetNonExistentShippingAddressFromAddressBook()
{
$maskedQuoteId = $this->assignQuoteToCustomer();

Expand Down Expand Up @@ -356,7 +316,7 @@ public function testSetShippingAddressIfCustomerIsNotOwnerOfAddress()
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
* @expectedException \Exception
*/
public function testSetShippingAddressIfCustomerIsNotOwnerOfCart()
public function testSetShippingAddressToAnotherCustomerCart()
{
$maskedQuoteId = $this->assignQuoteToCustomer('test_order_with_simple_product_without_address', 1);

Expand Down Expand Up @@ -388,19 +348,116 @@ public function testSetShippingAddressIfCustomerIsNotOwnerOfCart()
}

/**
* TODO: currently only the city param is required, do we need to add at least ZIP code?
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
* @magentoApiDataFixture Magento/Customer/_files/customer.php
* @dataProvider dataProviderUpdateWithMissedRequiredParameters
* @param string $input
* @param string $message
* @throws \Exception
*/
public function testSetNewShippingAddressWithMissedRequiredParameters(string $input, string $message)
{
$maskedQuoteId = $this->assignQuoteToCustomer();

$query = <<<QUERY
mutation {
setShippingAddressesOnCart(
input: {
cart_id: "{$maskedQuoteId}"
shipping_addresses: [
{
{$input}
}
]
}
) {
cart {
shipping_addresses {
city
}
}
}
}
QUERY;
$this->expectExceptionMessage($message);
$this->graphQlQuery($query, [], '', $this->getHeaderMap());
}

/**
* @return array
*/
public function requestWithoutRequiredParamsDataProvider()
public function dataProviderUpdateWithMissedRequiredParameters()
{
return [
[
'save_in_address_book: false',
'shipping_addresses' => [
'',
'The shipping address must contain either "customer_address_id" or "address".',
],
'missed_city' => [
'address: { save_in_address_book: false }',
'Field CartAddressInput.city of required type String! was not provided'
]
];
}

/**
* @magentoApiDataFixture Magento/Customer/_files/customer.php
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
* @expectedException \Exception
* @expectedExceptionMessage You cannot specify multiple shipping addresses.
*/
public function testSetMultipleNewShippingAddresses()
{
$maskedQuoteId = $this->assignQuoteToCustomer();

$query = <<<QUERY
mutation {
setShippingAddressesOnCart(
input: {
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
}
}
]
}
) {
cart {
shipping_addresses {
city
}
}
}
}
QUERY;
$this->graphQlQuery($query, [], '', $this->getHeaderMap());
}

/**
* Verify the all the whitelisted fields for a New Address Object
*
Expand Down
Loading

0 comments on commit 5f3d076

Please sign in to comment.