Skip to content

Commit e8c7816

Browse files
committed
AC-9030::Fedex API Upgrade - Fix WebAPI Functional test case failure
1 parent 75fd49a commit e8c7816

16 files changed

+1582
-5068
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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+
namespace Magento\TestModuleFedex\Model;
9+
10+
/**
11+
* Mock Fedex soap client factory
12+
*/
13+
class MockCurlClient extends \Magento\Framework\HTTP\Client\Curl
14+
{
15+
/**
16+
* @var MockResponseBodyLoader
17+
*/
18+
private $mockResponseBodyLoader;
19+
20+
/**
21+
* Oauth End point to get Access Token
22+
*
23+
* @var string
24+
*/
25+
private const OAUTH_REQUEST_END_POINT = 'oauth/token';
26+
27+
/**
28+
* REST end point for Rate API
29+
*
30+
* @var string
31+
*/
32+
private const RATE_REQUEST_END_POINT = 'rate/v1/rates/quotes';
33+
34+
/**
35+
* @param MockResponseBodyLoader $mockResponseBodyLoader
36+
*/
37+
public function __construct(
38+
MockResponseBodyLoader $mockResponseBodyLoader,
39+
) {
40+
$this->mockResponseBodyLoader = $mockResponseBodyLoader;
41+
}
42+
43+
/**
44+
* Fetch mock Fedex rates
45+
*
46+
* @param string $url
47+
* @param array $request
48+
* @return void
49+
* @throws \Magento\Framework\Exception\NotFoundException
50+
*/
51+
public function post($url, $request): void
52+
{
53+
if (strpos($url, self::OAUTH_REQUEST_END_POINT) !== false) {
54+
$this->_responseBody = $this->mockResponseBodyLoader->loadForAuthRequest();
55+
}
56+
57+
if (strpos($url, self::RATE_REQUEST_END_POINT) !== false) {
58+
$this->_responseBody = $this->mockResponseBodyLoader->loadForRestRequest(json_decode($request, true));
59+
}
60+
}
61+
}

dev/tests/api-functional/_files/Magento/TestModuleFedex/Model/MockSoapClientFactory.php renamed to dev/tests/api-functional/_files/Magento/TestModuleFedex/Model/MockCurlFactory.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,20 @@
1010
use Magento\Framework\App\ObjectManager;
1111

1212
/**
13-
* Mock Fedex soap client factory
13+
* Mock Fedex rest client factory
1414
*/
15-
class MockSoapClientFactory extends \Magento\Framework\Webapi\Soap\ClientFactory
15+
class MockCurlFactory extends \Magento\Framework\HTTP\Client\CurlFactory
1616
{
1717
/**
1818
* Create instance of the mock SoapClient
1919
*
20-
* @param string $wsdl
21-
* @param array $options
22-
* @return \SoapClient
2320
*/
24-
public function create($wsdl, array $options = []): \SoapClient
21+
public function create(array $data = [])
2522
{
2623
return ObjectManager::getInstance()->create(
27-
MockSoapClient::class,
24+
MockCurlClient::class,
2825
[
29-
'wsdl' => $wsdl,
30-
'options' => $options,
26+
'data' => $data
3127
]
3228
);
3329
}

dev/tests/api-functional/_files/Magento/TestModuleFedex/Model/MockResponseBodyLoader.php

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818
*/
1919
class MockResponseBodyLoader
2020
{
21-
private const RESPONSE_FILE_PATTERN = '%s/_files/mock_response_%s_%s.json';
22-
private const PATH_COUNTRY = 'RequestedShipment/Recipient/Address/CountryCode';
23-
private const PATH_SERVICE_TYPE = 'RequestedShipment/ServiceType';
21+
private const REST_RESPONSE_FILE_PATTERN = '%s/_files/mock_rest_response_%s_%s.json';
22+
private const REST_PATH_COUNTRY = 'requestedShipment/recipient/address/countryCode';
23+
private const REST_PATH_SERVICE_TYPE = 'requestedShipment/serviceType';
24+
private const REST_AUTH_RESPONSE_FILE = '%s/_files/mock_rest_response_auth.json';
2425

2526
/**
2627
* @var Dir
@@ -53,27 +54,42 @@ public function __construct(
5354
}
5455

5556
/**
56-
* Loads mock response xml for a given request
57+
* Loads mock json response for a given request
5758
*
5859
* @param array $request
5960
* @return string
6061
* @throws NotFoundException
6162
*/
62-
public function loadForRequest(array $request): string
63+
public function loadForRestRequest(array $request): string
6364
{
6465
$moduleDir = $this->moduleDirectory->getDir('Magento_TestModuleFedex');
6566

66-
$type = strtolower($this->arrayManager->get(static::PATH_SERVICE_TYPE, $request) ?? 'general');
67-
$country = strtolower($this->arrayManager->get(static::PATH_COUNTRY, $request) ?? '');
67+
$type = strtolower($this->arrayManager->get(static::REST_PATH_SERVICE_TYPE, $request) ?? 'general');
68+
$country = strtolower($this->arrayManager->get(static::REST_PATH_COUNTRY, $request) ?? '');
6869

69-
$responsePath = sprintf(static::RESPONSE_FILE_PATTERN, $moduleDir, $type, $country);
70+
$responsePath = sprintf(static::REST_RESPONSE_FILE_PATTERN, $moduleDir, $type, $country);
7071

7172
if (!$this->fileIo->fileExists($responsePath)) {
7273
throw new NotFoundException(
7374
__('"%1" is not a valid mock response type for country "%2".', $type, $country)
7475
);
7576
}
77+
return $this->fileIo->read($responsePath);
78+
}
79+
80+
/**
81+
* Loads mock response xml for a given request
82+
*/
83+
public function loadForAuthRequest()
84+
{
85+
$moduleDir = $this->moduleDirectory->getDir('Magento_TestModuleFedex');
86+
$responsePath = sprintf(static::REST_AUTH_RESPONSE_FILE, $moduleDir);
7687

88+
if (!$this->fileIo->fileExists($responsePath)) {
89+
throw new NotFoundException(
90+
__('No valid mock response found for Authentication.')
91+
);
92+
}
7793
return $this->fileIo->read($responsePath);
7894
}
7995
}

dev/tests/api-functional/_files/Magento/TestModuleFedex/Model/MockSoapClient.php

Lines changed: 0 additions & 47 deletions
This file was deleted.

0 commit comments

Comments
 (0)