1
0
mirror of synced 2024-11-25 23:06:07 +03:00

add update-scopes method

This commit is contained in:
Pavel 2023-01-20 12:53:14 +03:00 committed by GitHub
commit e973d605f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 94 additions and 0 deletions

View File

@ -73,4 +73,38 @@ trait Module
['integrationModule' => json_encode($configuration)] ['integrationModule' => json_encode($configuration)]
); );
} }
/**
* Update scopes
*
* @param string $code
* @param array $requires
*
* @throws \RetailCrm\Exception\InvalidJsonException
* @throws \RetailCrm\Exception\CurlException
* @throws \InvalidArgumentException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function integrationModulesUpdateScopes($code, array $requires)
{
if (empty($code)) {
throw new \InvalidArgumentException(
'Parameter `code` must be set'
);
}
if (!count($requires) || empty($requires['scopes'])) {
throw new \InvalidArgumentException(
'Parameter `requires` must contains a data & configuration `scopes` must be set'
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
sprintf('/integration-modules/%s/update-scopes', $code),
"POST",
['requires' => json_encode($requires)]
);
}
} }

View File

@ -0,0 +1,60 @@
<?php
namespace RetailCrm\Tests\Methods\Version5;
use RetailCrm\Response\ApiResponse;
use RetailCrm\Test\TestCase;
/**
* Class ApiClientModulesTest
*
* @category RetailCrm
* @package RetailCrm
*/
class ApiClientModuleTest extends TestCase
{
/**
* Test configuration
*
* @group module_v5
*
* @return void
*/
public function testUpdateScopes()
{
$integrationCode = 'integration_v5';
$stub = $this->getMockBuilder(\RetailCrm\Http\Client::class)
->disableOriginalConstructor()
->setMethods(['makeRequest'])
->getMock();
$requires = [
'scopes' => [
"integration_read",
"integration_write"
],
];
$stub->expects(self::once())
->method('makeRequest')
->with(
sprintf('/integration-modules/%s/update-scopes', $integrationCode),
"POST",
['requires' => json_encode($requires)]
)
->willReturn(
(new ApiResponse(200, json_encode(['success' => true, 'apiKey' => 'test key'])))
->asJsonResponse()
)
;
$client = static::getMockedApiClient($stub);
/** @var \RetailCrm\Response\ApiResponse $response */
$response = $client->request->integrationModulesUpdateScopes($integrationCode, $requires);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals($response->getStatusCode(), 200);
static::assertTrue($response->isSuccessful());
static::assertNotEmpty($response['apiKey']);
}
}