Skip to content

Commit 6d71e5c

Browse files
author
Vaha
committed
magento#682: [Test coverage] added test cases for missed parameters at 'setBillingAddressMutation'
1 parent 02bca98 commit 6d71e5c

File tree

3 files changed

+190
-3
lines changed

3 files changed

+190
-3
lines changed

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

Lines changed: 83 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,89 @@ public function testSetNewBillingAddressAndFromAddressBookAtSameTime()
321321
$this->graphQlMutation($query, [], '', $this->getHeaderMap());
322322
}
323323

324+
/**
325+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
326+
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
327+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
328+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
329+
*/
330+
public function testSetNewBillingAddressWithoutCustomerAddressIdAndAddress()
331+
{
332+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
333+
334+
$query = <<<QUERY
335+
mutation {
336+
setBillingAddressOnCart(
337+
input: {
338+
cart_id: "$maskedQuoteId"
339+
billing_address: {
340+
use_for_shipping: true
341+
}
342+
}
343+
) {
344+
cart {
345+
billing_address {
346+
city
347+
}
348+
}
349+
}
350+
}
351+
QUERY;
352+
353+
self::expectExceptionMessage(
354+
'The billing address must contain either "customer_address_id" or "address".'
355+
);
356+
$this->graphQlMutation($query, [], '', $this->getHeaderMap());
357+
}
358+
359+
/**
360+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
361+
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
362+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
363+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
364+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_multishipping_with_two_shipping_addresses.php
365+
*/
366+
public function testSetNewBillingAddressWithUseForShippingAndMultishipping()
367+
{
368+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
369+
370+
$query = <<<QUERY
371+
mutation {
372+
setBillingAddressOnCart(
373+
input: {
374+
cart_id: "$maskedQuoteId"
375+
billing_address: {
376+
address: {
377+
firstname: "test firstname"
378+
lastname: "test lastname"
379+
company: "test company"
380+
street: ["test street 1", "test street 2"]
381+
city: "test city"
382+
region: "test region"
383+
postcode: "887766"
384+
country_code: "US"
385+
telephone: "88776655"
386+
save_in_address_book: false
387+
}
388+
use_for_shipping: true
389+
}
390+
}
391+
) {
392+
cart {
393+
billing_address {
394+
city
395+
}
396+
}
397+
}
398+
}
399+
QUERY;
400+
401+
self::expectExceptionMessage(
402+
'Using the "use_for_shipping" option with multishipping is not possible.'
403+
);
404+
$this->graphQlMutation($query, [], '', $this->getHeaderMap());
405+
}
406+
324407
/**
325408
* _security
326409
* @magentoApiDataFixture Magento/Customer/_files/customer.php
@@ -470,9 +553,6 @@ public function testSetBillingAddressOnNonExistentCart()
470553
*/
471554
public function testSetBillingAddressWithoutRequiredParameters(string $input, string $message)
472555
{
473-
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
474-
$input = str_replace('cart_id_value', $maskedQuoteId, $input);
475-
476556
$query = <<<QUERY
477557
mutation {
478558
setBillingAddressOnCart(

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

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,87 @@ public function dataProviderSetWithoutRequiredParameters(): array
331331
];
332332
}
333333

334+
/**
335+
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
336+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
337+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
338+
*/
339+
public function testSetNewBillingAddressWithoutCustomerAddressIdAndAddress()
340+
{
341+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
342+
343+
$query = <<<QUERY
344+
mutation {
345+
setBillingAddressOnCart(
346+
input: {
347+
cart_id: "$maskedQuoteId"
348+
billing_address: {
349+
use_for_shipping: true
350+
}
351+
}
352+
) {
353+
cart {
354+
billing_address {
355+
city
356+
}
357+
}
358+
}
359+
}
360+
QUERY;
361+
362+
self::expectExceptionMessage(
363+
'The billing address must contain either "customer_address_id" or "address".'
364+
);
365+
$this->graphQlMutation($query);
366+
}
367+
368+
/**
369+
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
370+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
371+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
372+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_multishipping_with_two_shipping_addresses.php
373+
*/
374+
public function testSetNewBillingAddressWithUseForShippingAndMultishipping()
375+
{
376+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
377+
378+
$query = <<<QUERY
379+
mutation {
380+
setBillingAddressOnCart(
381+
input: {
382+
cart_id: "$maskedQuoteId"
383+
billing_address: {
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+
use_for_shipping: true
397+
}
398+
}
399+
) {
400+
cart {
401+
billing_address {
402+
city
403+
}
404+
}
405+
}
406+
}
407+
QUERY;
408+
409+
self::expectExceptionMessage(
410+
'Using the "use_for_shipping" option with multishipping is not possible.'
411+
);
412+
$this->graphQlMutation($query);
413+
}
414+
334415
/**
335416
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
336417
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
use Magento\Quote\Api\CartRepositoryInterface;
9+
use Magento\Quote\Model\QuoteFactory;
10+
use Magento\Quote\Model\ResourceModel\Quote as QuoteResource;
11+
use Magento\TestFramework\Helper\Bootstrap;
12+
13+
/** @var QuoteFactory $quoteFactory */
14+
$quoteFactory = Bootstrap::getObjectManager()->get(QuoteFactory::class);
15+
/** @var QuoteResource $quoteResource */
16+
$quoteResource = Bootstrap::getObjectManager()->get(QuoteResource::class);
17+
18+
$quote = $quoteFactory->create();
19+
$quoteResource->load($quote, 'test_quote', 'reserved_order_id');
20+
21+
require __DIR__ . '/../../../Multishipping/Fixtures/shipping_address_list.php';
22+
23+
/** @var CartRepositoryInterface $quoteRepository */
24+
$quoteRepository = $objectManager->get(CartRepositoryInterface::class);
25+
$quote->collectTotals();
26+
$quoteRepository->save($quote);

0 commit comments

Comments
 (0)