Skip to content

Commit d1b38c2

Browse files
AnujNehraAnujNehra
authored andcommitted
ACP2E-1986: Rest api V1/carts/mine/estimate-shipping-methods show 500 Error
1 parent 1ed0393 commit d1b38c2

File tree

1 file changed

+69
-2
lines changed

1 file changed

+69
-2
lines changed

lib/internal/Magento/Framework/Webapi/Test/Unit/ServiceInputProcessorTest.php

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\Framework\Api\AttributeValueFactory;
1313
use \Magento\Framework\Api\SearchCriteriaInterface;
1414
use Magento\Framework\App\Cache\Type\Reflection;
15+
use Magento\Framework\Exception\InputException;
1516
use Magento\Framework\Exception\InvalidArgumentException;
1617
use Magento\Framework\ObjectManagerInterface;
1718
use Magento\Framework\Reflection\FieldNamer;
@@ -20,6 +21,7 @@
2021
use Magento\Framework\Reflection\TypeProcessor;
2122
use Magento\Framework\Serialize\SerializerInterface;
2223
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
24+
use Magento\Framework\Webapi\Exception;
2325
use Magento\Framework\Webapi\Validator\IOLimit\DefaultPageSizeSetter;
2426
use Magento\Framework\Webapi\ServiceInputProcessor;
2527
use Magento\Framework\Webapi\Validator\IOLimit\IOLimitConfigProvider;
@@ -40,6 +42,8 @@
4042
use PHPUnit\Framework\MockObject\MockObject;
4143
use PHPUnit\Framework\TestCase;
4244
use Magento\Framework\Webapi\Validator\EntityArrayValidator\InputArraySizeLimitValue;
45+
use Magento\Quote\Api\ShipmentEstimationInterface;
46+
use Magento\Quote\Api\Data\AddressInterface;
4347

4448
/**
4549
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -84,16 +88,23 @@ class ServiceInputProcessorTest extends TestCase
8488
*/
8589
private $defaultPageSizeSetter;
8690

91+
/**
92+
* @var AddressInterface|MockObject
93+
*/
94+
protected $addressMock;
95+
8796
/**
8897
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
8998
*/
9099
protected function setUp(): void
91100
{
92101
$this->searchCriteria = self::getMockBuilder(SearchCriteriaInterface::class)
93102
->getMock();
94-
103+
$this->addressMock = self::getMockBuilder(AddressInterface::class)
104+
->getMock();
95105
$objectManagerStatic = [
96-
SearchCriteriaInterface::class => $this->searchCriteria
106+
SearchCriteriaInterface::class => $this->searchCriteria,
107+
AddressInterface::class => $this->addressMock
97108
];
98109
$objectManager = new ObjectManager($this);
99110
$this->objectManagerMock = $this->getMockBuilder(ObjectManagerInterface::class)
@@ -701,4 +712,60 @@ public function invalidCustomAttributesDataProvider()
701712
]
702713
];
703714
}
715+
716+
/**
717+
* @return array
718+
*/
719+
public function payloadDataProvider(): array
720+
{
721+
return [
722+
[
723+
[
724+
'address' => [
725+
"street" => [
726+
"서울 강북구 한천로166길 2 (-서울 강북구 수유동 269-36)"
727+
],
728+
"city." => "pune",
729+
],
730+
'cartId' => "30"
731+
],
732+
1
733+
],
734+
[
735+
[
736+
'address' => [
737+
"street" => [
738+
"서울 강북구 한천로166길 2 (-서울 강북구 수유동 269-36)"
739+
],
740+
"city" => "pune",
741+
],
742+
'cartId' => "30"
743+
],
744+
0
745+
]
746+
];
747+
}
748+
749+
/**
750+
* Validate if payload has correct attributes
751+
*
752+
* @param array $payload
753+
* @param int $exception
754+
* @return void
755+
* @throws Exception
756+
* @dataProvider payloadDataProvider
757+
*/
758+
public function testValidateApiPayload(array $payload, int $exception): void
759+
{
760+
if ($exception) {
761+
$this->expectException(InputException::class);
762+
$this->expectExceptionMessage('"City." is required. Enter and try again.');
763+
}
764+
$result = $this->serviceInputProcessor->process(
765+
ShipmentEstimationInterface::class,
766+
'estimateByExtendedAddress',
767+
$payload
768+
);
769+
$this->assertNotEmpty($result);
770+
}
704771
}

0 commit comments

Comments
 (0)