Skip to content

Commit 39d0e09

Browse files
authored
Merge pull request magento#5 from magento-tsg/MC-39574
[Arrows] MC-39574: Link to the Configuration is not displayed in "Search for Adobe Stock" window when API keys are not set
2 parents dd7c94b + b3366f2 commit 39d0e09

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

AdobeStockClient/Model/ConnectionWrapper.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ private function handleException(\Exception $exception, string $message): \Excep
128128
if (strpos($exception->getMessage(), 'Api Key is invalid') !== false) {
129129
return new AuthenticationException(__('Adobe API Key is invalid!'));
130130
}
131+
if (strpos($exception->getMessage(), 'Api Key is required') !== false) {
132+
return new AuthenticationException(__('Adobe Api Key is required!'));
133+
}
131134
if (strpos($exception->getMessage(), 'Oauth token is not valid') !== false) {
132135
$this->flushUserTokens->execute();
133136
return new AuthorizationException(__('Adobe API login has expired!'));

AdobeStockClient/Test/Unit/Model/ConnectionWrapperTest.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
use Magento\AdobeStockClient\Model\ConnectionFactory;
2020
use Magento\AdobeStockClient\Model\ConnectionWrapper;
2121
use Magento\AdobeStockClientApi\Api\ConfigInterface;
22+
use Magento\Framework\Exception\AuthenticationException;
23+
use Magento\Framework\Exception\AuthorizationException;
2224
use PHPUnit\Framework\MockObject\MockObject;
2325
use PHPUnit\Framework\TestCase;
2426

@@ -163,6 +165,30 @@ public function testGetNextResponseWithException(): void
163165
$this->connectionWrapper->getNextResponse();
164166
}
165167

168+
/**
169+
* Next response with exception that should be explained in more detail
170+
*
171+
* @param string $connectionException Exception message thrown by the connection
172+
* @param string $thrownException Exception message that will throws by the getNextResponse method
173+
* @param string $exception Exception class that will throws by the getNextResponse method
174+
*
175+
* @return void
176+
* @dataProvider detailedExceptionsForGetNextResponseProvider
177+
*/
178+
public function testGetNextResponseWithExceptionThatNeedMoreAttention(
179+
string $connectionException,
180+
string $thrownException,
181+
string $exception
182+
): void {
183+
$this->expectException($exception);
184+
$this->expectExceptionMessage($thrownException);
185+
$this->imsConfig->method('getApiKey')
186+
->willReturn('key');
187+
$this->adobeStockMock->method('getNextResponse')
188+
->willThrowException(new \Exception('Beginning of the exception message ' . $connectionException));
189+
$this->connectionWrapper->getNextResponse();
190+
}
191+
166192
/**
167193
* Get member profile test
168194
*/
@@ -258,6 +284,37 @@ public function testFlushTokens(): void
258284
$this->connectionWrapper->downloadAssetUrl(new LicenseRequest());
259285
}
260286

287+
/**
288+
* Provider of exceptions that need more attention in getNextResponse method
289+
*
290+
* @return array
291+
*/
292+
public function detailedExceptionsForGetNextResponseProvider(): array
293+
{
294+
return [
295+
[
296+
'connection_exception_message' => 'Api Key is invalid',
297+
'thrown_exception_message' => 'Adobe API Key is invalid!',
298+
'thrown_exception' => AuthenticationException::class,
299+
],
300+
[
301+
'connection_exception_message' => 'Api Key is required',
302+
'thrown_exception_message' => 'Adobe Api Key is required!',
303+
'thrown_exception' => AuthenticationException::class,
304+
],
305+
[
306+
'connection_exception_message' => 'Oauth token is not valid',
307+
'thrown_exception_message' => 'Adobe API login has expired!',
308+
'thrown_exception' => AuthorizationException::class,
309+
],
310+
[
311+
'connection_exception_message' => 'Could not validate the oauth token',
312+
'thrown_exception_message' => 'Adobe API login has expired!',
313+
'thrown_exception' => AuthorizationException::class,
314+
],
315+
];
316+
}
317+
261318
/**
262319
* Ste's tokens
263320
*/

0 commit comments

Comments
 (0)