From 13caebdbc252274a2977d7062f3b08a18afddda6 Mon Sep 17 00:00:00 2001 From: Andrey Date: Fri, 1 Apr 2022 17:26:14 +0300 Subject: [PATCH] Add update-scopes method to integration group (#142) Co-authored-by: Andrey Muriy --- src/Model/Entity/Integration/Requires.php | 29 ++++++++ .../IntegrationModuleUpdateScopesRequest.php | 34 +++++++++ .../IntegrationModuleUpdateScopesResponse.php | 30 ++++++++ src/ResourceGroup/Integration.php | 69 +++++++++++++++++++ tests/src/ResourceGroup/IntegrationTests.php | 29 ++++++++ 5 files changed, 191 insertions(+) create mode 100644 src/Model/Entity/Integration/Requires.php create mode 100644 src/Model/Request/Integration/IntegrationModuleUpdateScopesRequest.php create mode 100644 src/Model/Response/Integration/IntegrationModuleUpdateScopesResponse.php diff --git a/src/Model/Entity/Integration/Requires.php b/src/Model/Entity/Integration/Requires.php new file mode 100644 index 0000000..05c1cde --- /dev/null +++ b/src/Model/Entity/Integration/Requires.php @@ -0,0 +1,29 @@ +requires = $requires; + } +} diff --git a/src/Model/Response/Integration/IntegrationModuleUpdateScopesResponse.php b/src/Model/Response/Integration/IntegrationModuleUpdateScopesResponse.php new file mode 100644 index 0000000..81ddfc4 --- /dev/null +++ b/src/Model/Response/Integration/IntegrationModuleUpdateScopesResponse.php @@ -0,0 +1,30 @@ +integration->edit('test-integration', $request); + * } catch (ApiExceptionInterface $exception) { + * echo sprintf( + * 'Error from RetailCRM API (status code: %d): %s', + * $exception->getStatusCode(), + * $exception->getMessage() + * ); + * + * if (count($exception->getErrorResponse()->errors) > 0) { + * echo PHP_EOL . 'Errors: ' . implode(', ', $exception->getErrorResponse()->errors); + * } + * + * return; + * } + * + * echo 'Info: ' . print_r($response->info, true); + * ``` + * + * @param string $code + * @param \RetailCrm\Api\Model\Request\Integration\IntegrationModuleUpdateScopesRequest $request + * + * @return \RetailCrm\Api\Model\Response\Integration\IntegrationModuleUpdateScopesResponse + * @throws \RetailCrm\Api\Interfaces\ApiExceptionInterface + * @throws \RetailCrm\Api\Interfaces\ClientExceptionInterface + * @throws \RetailCrm\Api\Exception\Api\AccountDoesNotExistException + * @throws \RetailCrm\Api\Exception\Api\ApiErrorException + * @throws \RetailCrm\Api\Exception\Api\MissingCredentialsException + * @throws \RetailCrm\Api\Exception\Api\MissingParameterException + * @throws \RetailCrm\Api\Exception\Api\ValidationException + * @throws \RetailCrm\Api\Exception\Client\HandlerException + * @throws \RetailCrm\Api\Exception\Client\HttpClientException + */ + public function updateScopes( + string $code, + IntegrationModuleUpdateScopesRequest $request + ): IntegrationModuleUpdateScopesResponse { + /** @var IntegrationModuleUpdateScopesResponse $response */ + $response = $this->sendRequest( + RequestMethod::POST, + 'integration-modules/' . $code . '/update-scopes', + $request, + IntegrationModuleUpdateScopesResponse::class + ); + return $response; + } } diff --git a/tests/src/ResourceGroup/IntegrationTests.php b/tests/src/ResourceGroup/IntegrationTests.php index 28adc0e..2a0a19b 100644 --- a/tests/src/ResourceGroup/IntegrationTests.php +++ b/tests/src/ResourceGroup/IntegrationTests.php @@ -19,8 +19,10 @@ use RetailCrm\Api\Model\Entity\Integration\Integrations; use RetailCrm\Api\Model\Entity\Integration\Payment\Actions; use RetailCrm\Api\Model\Entity\Integration\Payment\PaymentConfiguration; use RetailCrm\Api\Model\Entity\Integration\Payment\Shop; +use RetailCrm\Api\Model\Entity\Integration\Requires; use RetailCrm\Api\Model\Entity\Integration\Transport\TransportConfiguration; use RetailCrm\Api\Model\Request\Integration\IntegrationModulesEditRequest; +use RetailCrm\Api\Model\Request\Integration\IntegrationModuleUpdateScopesRequest; use RetailCrm\TestUtils\Factory\TestClientFactory; use RetailCrm\TestUtils\TestCase\AbstractApiResourceGroupTestCase; @@ -293,4 +295,31 @@ EOF; return $statusList; } + + public function testUpdateScopes(): void + { + $json = <<<'EOF' +{ + "success": true, + "apiKey": "SOMEAPIKEY" +} +EOF; + $requires = new Requires(); + $requires->scopes = [ + 'integration_read', + 'integration_write', + ]; + $request = new IntegrationModuleUpdateScopesRequest($requires); + + $mock = static::createApiMockBuilder('integration-modules/test-integration/update-scopes'); + $mock->matchMethod(RequestMethod::POST) + ->matchBody(static::encodeForm($request)) + ->reply(200) + ->withBody($json); + + $client = TestClientFactory::createClient($mock->getClient()); + $response = $client->integration->updateScopes('test-integration', $request); + + self::assertModelEqualsToResponse($json, $response); + } }