Skip to content

Commit fbcf744

Browse files
authored
ENGCOM-5239: GraphQl-484: [Test Coverage] 'SetShippingAddressOnCart' functionality #703
2 parents bb3cede + 5081918 commit fbcf744

File tree

2 files changed

+138
-27
lines changed

2 files changed

+138
-27
lines changed

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

Lines changed: 85 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -383,23 +383,19 @@ public function testSetShippingAddressToAnotherCustomerCart()
383383
public function testSetNewShippingAddressWithMissedRequiredParameters(string $input, string $message)
384384
{
385385
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
386+
$input = str_replace('cart_id_value', $maskedQuoteId, $input);
386387

387388
$query = <<<QUERY
388389
mutation {
389390
setShippingAddressesOnCart(
390391
input: {
391-
cart_id: "{$maskedQuoteId}"
392-
shipping_addresses: [
393-
{
394-
{$input}
395-
}
396-
]
392+
{$input}
397393
}
398394
) {
399395
cart {
400-
shipping_addresses {
401-
city
402-
}
396+
shipping_addresses {
397+
city
398+
}
403399
}
404400
}
405401
}
@@ -414,13 +410,18 @@ public function testSetNewShippingAddressWithMissedRequiredParameters(string $in
414410
public function dataProviderUpdateWithMissedRequiredParameters(): array
415411
{
416412
return [
417-
'shipping_addresses' => [
418-
'',
419-
'The shipping address must contain either "customer_address_id" or "address".',
413+
'missed_shipping_addresses' => [
414+
'cart_id: "cart_id_value"',
415+
'Field SetShippingAddressesOnCartInput.shipping_addresses of required type [ShippingAddressInput]! ' .
416+
'was not provided.',
420417
],
421418
'missed_city' => [
422-
'address: { save_in_address_book: false }',
419+
'shipping_addresses: [ { address: { save_in_address_book: false } } ]',
423420
'Field CartAddressInput.city of required type String! was not provided'
421+
],
422+
'missed_cart_id' => [
423+
'shipping_addresses: {}',
424+
'Required parameter "cart_id" is missing'
424425
]
425426
];
426427
}
@@ -532,6 +533,75 @@ public function testSetNewShippingAddressOnCartWithRedundantStreetLine()
532533
$this->graphQlMutation($query, [], '', $this->getHeaderMap());
533534
}
534535

536+
/**
537+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
538+
* @magentoApiDataFixture Magento/Customer/_files/customer_address.php
539+
* @expectedException \Exception
540+
* @expectedExceptionMessage Could not find a cart with ID "non_existent_masked_id"
541+
*/
542+
public function testSetShippingAddressOnNonExistentCart()
543+
{
544+
$maskedQuoteId = 'non_existent_masked_id';
545+
$query = <<<QUERY
546+
mutation {
547+
setShippingAddressesOnCart(
548+
input: {
549+
cart_id: "$maskedQuoteId"
550+
shipping_addresses: [
551+
{
552+
customer_address_id: 1
553+
}
554+
]
555+
}
556+
) {
557+
cart {
558+
shipping_addresses {
559+
city
560+
}
561+
}
562+
}
563+
}
564+
QUERY;
565+
$this->graphQlMutation($query, [], '', $this->getHeaderMap());
566+
}
567+
568+
/**
569+
* _security
570+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
571+
* @magentoApiDataFixture Magento/Customer/_files/customer_address.php
572+
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
573+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
574+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
575+
*/
576+
public function testSetShippingAddressToGuestCart()
577+
{
578+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
579+
580+
$query = <<<QUERY
581+
mutation {
582+
setShippingAddressesOnCart(
583+
input: {
584+
cart_id: "$maskedQuoteId"
585+
shipping_addresses: {
586+
customer_address_id: 1
587+
}
588+
}
589+
) {
590+
cart {
591+
shipping_addresses {
592+
city
593+
}
594+
}
595+
}
596+
}
597+
QUERY;
598+
$this->expectExceptionMessage(
599+
"The current user cannot perform operations on cart \"{$maskedQuoteId}\""
600+
);
601+
602+
$this->graphQlMutation($query, [], '', $this->getHeaderMap());
603+
}
604+
535605
/**
536606
* Verify the all the whitelisted fields for a New Address Object
537607
*
@@ -594,7 +664,8 @@ private function getHeaderMap(string $username = 'customer@example.com', string
594664
private function assignQuoteToCustomer(
595665
string $reservedOrderId = 'test_order_with_simple_product_without_address',
596666
int $customerId = 1
597-
): string {
667+
): string
668+
{
598669
$quote = $this->quoteFactory->create();
599670
$this->quoteResource->load($quote, $reservedOrderId, 'reserved_order_id');
600671
$quote->setCustomerId($customerId);

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

Lines changed: 53 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -221,23 +221,19 @@ public function testSetShippingAddressToCustomerCart()
221221
public function testSetNewShippingAddressWithMissedRequiredParameters(string $input, string $message)
222222
{
223223
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
224+
$input = str_replace('cart_id_value', $maskedQuoteId, $input);
224225

225226
$query = <<<QUERY
226227
mutation {
227228
setShippingAddressesOnCart(
228229
input: {
229-
cart_id: "{$maskedQuoteId}"
230-
shipping_addresses: [
231-
{
232-
{$input}
233-
}
234-
]
230+
{$input}
235231
}
236232
) {
237233
cart {
238-
shipping_addresses {
239-
city
240-
}
234+
shipping_addresses {
235+
city
236+
}
241237
}
242238
}
243239
}
@@ -296,13 +292,18 @@ public function testSetNewShippingAddressOnCartWithRedundantStreetLine()
296292
public function dataProviderUpdateWithMissedRequiredParameters(): array
297293
{
298294
return [
299-
'shipping_addresses' => [
300-
'',
301-
'The shipping address must contain either "customer_address_id" or "address".',
295+
'missed_shipping_addresses' => [
296+
'cart_id: "cart_id_value"',
297+
'Field SetShippingAddressesOnCartInput.shipping_addresses of required type [ShippingAddressInput]! ' .
298+
'was not provided.',
302299
],
303300
'missed_city' => [
304-
'address: { save_in_address_book: false }',
301+
'shipping_addresses: [ { address: { save_in_address_book: false } } ]',
305302
'Field CartAddressInput.city of required type String! was not provided'
303+
],
304+
'missed_cart_id' => [
305+
'shipping_addresses: {}',
306+
'Required parameter "cart_id" is missing'
306307
]
307308
];
308309
}
@@ -367,6 +368,45 @@ public function testSetMultipleNewShippingAddresses()
367368
$this->graphQlMutation($query);
368369
}
369370

371+
/**
372+
* @expectedException \Exception
373+
* @expectedExceptionMessage Could not find a cart with ID "non_existent_masked_id"
374+
*/
375+
public function testSetShippingAddressOnNonExistentCart()
376+
{
377+
$maskedQuoteId = 'non_existent_masked_id';
378+
$query = <<<QUERY
379+
mutation {
380+
setShippingAddressesOnCart(
381+
input: {
382+
cart_id: "$maskedQuoteId"
383+
shipping_addresses: {
384+
address: {
385+
firstname: "test firstname"
386+
lastname: "test lastname"
387+
company: "test company"
388+
street: ["test street 1", "test street 2"]
389+
city: "test city"
390+
region: "test region"
391+
postcode: "887766"
392+
country_code: "US"
393+
telephone: "88776655"
394+
save_in_address_book: false
395+
}
396+
}
397+
}
398+
) {
399+
cart {
400+
shipping_addresses {
401+
city
402+
}
403+
}
404+
}
405+
}
406+
QUERY;
407+
$this->graphQlMutation($query);
408+
}
409+
370410
/**
371411
* Verify the all the whitelisted fields for a New Address Object
372412
*

0 commit comments

Comments
 (0)