Skip to content

Commit 69d3a09

Browse files
committed
ACP2E-4156: For Shipping Information Server Side Validation is not Working using REST API
1 parent d945c13 commit 69d3a09

File tree

2 files changed

+14
-44
lines changed

2 files changed

+14
-44
lines changed

app/code/Magento/Checkout/Test/Unit/Model/GuestShippingInformationManagementTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Checkout\Api\Data\ShippingInformationInterface;
1212
use Magento\Checkout\Api\ShippingInformationManagementInterface;
1313
use Magento\Checkout\Model\GuestShippingInformationManagement;
14+
use Magento\Customer\Model\Address;
1415
use Magento\Customer\Model\AddressFactory;
1516
use Magento\Framework\Exception\InputException;
1617
use Magento\Framework\Validator\Factory as ValidatorFactory;
@@ -89,7 +90,7 @@ public function testSaveAddressInformation()
8990
$billingAddressMock->expects($this->once())
9091
->method('getExtensionAttributes')
9192
->willReturn(null);
92-
$customerAddressMock = $this->createMock(\Magento\Customer\Model\Address::class);
93+
$customerAddressMock = $this->createMock(Address::class);
9394
$this->addressFactoryMock->expects($this->exactly(2))
9495
->method('create')
9596
->willReturn($customerAddressMock);
@@ -138,7 +139,7 @@ public function testSaveAddressInformationWithInvalidAddress()
138139
$addressInformationMock->expects($this->never())
139140
->method('getBillingAddress');
140141
$shippingAddressMock->method('getExtensionAttributes')->willReturn(null);
141-
$customerAddressMock = $this->createMock(\Magento\Customer\Model\Address::class);
142+
$customerAddressMock = $this->createMock(Address::class);
142143
$this->addressFactoryMock->expects($this->once())->method('create')->willReturn($customerAddressMock);
143144
$validatorMock = $this->createMock(ValidatorInterface::class);
144145
$this->validatorFactoryMock->expects($this->once())

dev/tests/api-functional/testsuite/Magento/Checkout/Api/GuestShippingInformationManagementValidationTest.php

Lines changed: 11 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
namespace Magento\Checkout\Api;
99

1010
use Magento\Framework\Webapi\Rest\Request;
11+
use Magento\Catalog\Test\Fixture\Product as ProductFixture;
12+
use Magento\Quote\Test\Fixture\GuestCart as GuestCartFixture;
13+
use Magento\Quote\Test\Fixture\AddProductToCart as AddProductToCartFixture;
14+
use Magento\Checkout\Test\Fixture\SetBillingAddress as SetBillingAddressFixture;
15+
use Magento\TestFramework\Fixture\DataFixture;
1116
use Magento\TestFramework\TestCase\WebapiAbstract;
1217
use Magento\TestFramework\Helper\Bootstrap;
1318
use Magento\Quote\Model\Quote;
@@ -50,50 +55,14 @@ protected function setUp(): void
5055
$this->quoteIdMaskFactory = Bootstrap::getObjectManager()->get(QuoteIdMaskFactory::class);
5156
}
5257

53-
/**
54-
* Test validation of required fields in shipping address
55-
*
56-
* @magentoApiDataFixture Magento/Sales/_files/quote.php
57-
*/
58-
public function testSaveAddressInformationWithMissingRequiredFields()
59-
{
60-
$this->expectException(\Exception::class);
61-
$this->expectExceptionMessage('The shipping address contains invalid data');
62-
$cartId = $this->getMaskedCartId('test01');
63-
$shippingAddress = $this->addressFactory->create();
64-
$shippingAddress->setData([
65-
'country_id' => 'US',
66-
'region_id' => 12,
67-
'region' => 'California',
68-
'region_code' => 'CA',
69-
'street' => ['123 Test Street'],
70-
'city' => 'Test City',
71-
'postcode' => '90210',
72-
'telephone' => '1234567890'
73-
]);
74-
$billingAddress = $this->addressFactory->create();
75-
$billingAddress->setData([
76-
'country_id' => 'US',
77-
'region_id' => 12,
78-
'region' => 'California',
79-
'region_code' => 'CA',
80-
'street' => ['123 Test Street'],
81-
'city' => 'Test City',
82-
'postcode' => '90210',
83-
'telephone' => '1234567890'
84-
]);
85-
$shippingInformation = $this->shippingInformationFactory->create();
86-
$shippingInformation->setShippingAddress($shippingAddress);
87-
$shippingInformation->setBillingAddress($billingAddress);
88-
$shippingInformation->setShippingMethodCode('flatrate');
89-
$shippingInformation->setShippingCarrierCode('flatrate');
90-
$this->callSaveAddressInformation($cartId, $shippingInformation);
91-
}
92-
58+
#[
59+
DataFixture(ProductFixture::class, as: 'p1'),
60+
DataFixture(GuestCartFixture::class, as: 'cart'),
61+
DataFixture(AddProductToCartFixture::class, ['cart_id' => '$cart.id$', 'product_id' => '$p1.id$']),
62+
DataFixture(SetBillingAddressFixture::class, ['cart_id' => '$cart.id$']),
63+
]
9364
/**
9465
* Test successful validation with valid address data
95-
*
96-
* @magentoApiDataFixture Magento/Sales/_files/quote.php
9766
*/
9867
public function testSaveAddressInformationWithValidData()
9968
{

0 commit comments

Comments
 (0)