Skip to content

Commit 5f3d076

Browse files
committed
GraphQL-427: Test coverage: SetShippingAddressOnCartTest
1 parent 32366e0 commit 5f3d076

File tree

2 files changed

+139
-150
lines changed

2 files changed

+139
-150
lines changed

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetShippingAddressOnCartTest.php

Lines changed: 104 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ protected function setUp()
4949
}
5050

5151
/**
52-
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
5352
* @magentoApiDataFixture Magento/Customer/_files/customer.php
53+
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
5454
*/
5555
public function testSetNewShippingAddress()
5656
{
@@ -107,46 +107,6 @@ public function testSetNewShippingAddress()
107107
$this->assertNewShippingAddressFields($shippingAddressResponse);
108108
}
109109

110-
/**
111-
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
112-
* @magentoApiDataFixture Magento/Customer/_files/customer.php
113-
* @dataProvider requestWithoutRequiredParamsDataProvider
114-
* @param string $params
115-
* @param string $expectedException
116-
* @throws \Exception
117-
*/
118-
public function testSetNewShippingAddressWithEmptyRequiredParams(string $params, string $expectedException)
119-
{
120-
$maskedQuoteId = $this->assignQuoteToCustomer();
121-
122-
$query = <<<QUERY
123-
mutation {
124-
setShippingAddressesOnCart(
125-
input: {
126-
cart_id: "$maskedQuoteId"
127-
shipping_addresses: [
128-
{
129-
address: {
130-
$params
131-
}
132-
}
133-
]
134-
}
135-
) {
136-
cart {
137-
shipping_addresses {
138-
city
139-
}
140-
}
141-
}
142-
}
143-
QUERY;
144-
$this->expectExceptionMessage(
145-
$expectedException
146-
);
147-
$this->graphQlQuery($query, [], '', $this->getHeaderMap());
148-
}
149-
150110
/**
151111
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_virtual_product_saved.php
152112
* @magentoApiDataFixture Magento/Customer/_files/customer.php
@@ -241,7 +201,7 @@ public function testSetShippingAddressFromAddressBook()
241201
* @expectedException \Exception
242202
* @expectedExceptionMessage Could not find a address with ID "100"
243203
*/
244-
public function testSetNotExistedShippingAddressFromAddressBook()
204+
public function testSetNonExistentShippingAddressFromAddressBook()
245205
{
246206
$maskedQuoteId = $this->assignQuoteToCustomer();
247207

@@ -356,7 +316,7 @@ public function testSetShippingAddressIfCustomerIsNotOwnerOfAddress()
356316
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
357317
* @expectedException \Exception
358318
*/
359-
public function testSetShippingAddressIfCustomerIsNotOwnerOfCart()
319+
public function testSetShippingAddressToAnotherCustomerCart()
360320
{
361321
$maskedQuoteId = $this->assignQuoteToCustomer('test_order_with_simple_product_without_address', 1);
362322

@@ -388,19 +348,116 @@ public function testSetShippingAddressIfCustomerIsNotOwnerOfCart()
388348
}
389349

390350
/**
391-
* TODO: currently only the city param is required, do we need to add at least ZIP code?
351+
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
352+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
353+
* @dataProvider dataProviderUpdateWithMissedRequiredParameters
354+
* @param string $input
355+
* @param string $message
356+
* @throws \Exception
357+
*/
358+
public function testSetNewShippingAddressWithMissedRequiredParameters(string $input, string $message)
359+
{
360+
$maskedQuoteId = $this->assignQuoteToCustomer();
361+
362+
$query = <<<QUERY
363+
mutation {
364+
setShippingAddressesOnCart(
365+
input: {
366+
cart_id: "{$maskedQuoteId}"
367+
shipping_addresses: [
368+
{
369+
{$input}
370+
}
371+
]
372+
}
373+
) {
374+
cart {
375+
shipping_addresses {
376+
city
377+
}
378+
}
379+
}
380+
}
381+
QUERY;
382+
$this->expectExceptionMessage($message);
383+
$this->graphQlQuery($query, [], '', $this->getHeaderMap());
384+
}
385+
386+
/**
392387
* @return array
393388
*/
394-
public function requestWithoutRequiredParamsDataProvider()
389+
public function dataProviderUpdateWithMissedRequiredParameters()
395390
{
396391
return [
397-
[
398-
'save_in_address_book: false',
392+
'shipping_addresses' => [
393+
'',
394+
'The shipping address must contain either "customer_address_id" or "address".',
395+
],
396+
'missed_city' => [
397+
'address: { save_in_address_book: false }',
399398
'Field CartAddressInput.city of required type String! was not provided'
400399
]
401400
];
402401
}
403402

403+
/**
404+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
405+
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
406+
* @expectedException \Exception
407+
* @expectedExceptionMessage You cannot specify multiple shipping addresses.
408+
*/
409+
public function testSetMultipleNewShippingAddresses()
410+
{
411+
$maskedQuoteId = $this->assignQuoteToCustomer();
412+
413+
$query = <<<QUERY
414+
mutation {
415+
setShippingAddressesOnCart(
416+
input: {
417+
cart_id: "$maskedQuoteId"
418+
shipping_addresses: [
419+
{
420+
address: {
421+
firstname: "test firstname"
422+
lastname: "test lastname"
423+
company: "test company"
424+
street: ["test street 1", "test street 2"]
425+
city: "test city"
426+
region: "test region"
427+
postcode: "887766"
428+
country_code: "US"
429+
telephone: "88776655"
430+
save_in_address_book: false
431+
}
432+
},
433+
{
434+
address: {
435+
firstname: "test firstname 2"
436+
lastname: "test lastname 2"
437+
company: "test company 2"
438+
street: ["test street 1", "test street 2"]
439+
city: "test city"
440+
region: "test region"
441+
postcode: "887766"
442+
country_code: "US"
443+
telephone: "88776655"
444+
save_in_address_book: false
445+
}
446+
}
447+
]
448+
}
449+
) {
450+
cart {
451+
shipping_addresses {
452+
city
453+
}
454+
}
455+
}
456+
}
457+
QUERY;
458+
$this->graphQlQuery($query, [], '', $this->getHeaderMap());
459+
}
460+
404461
/**
405462
* Verify the all the whitelisted fields for a New Address Object
406463
*

0 commit comments

Comments
 (0)