From f3db3fdb6312ec2e3ce9b09e2a2074a4027c1ec8 Mon Sep 17 00:00:00 2001 From: Vladimir Kolchin Date: Fri, 20 Jan 2023 08:31:25 +0100 Subject: [PATCH 1/3] add update-scopes method --- lib/RetailCrm/Methods/V5/Module.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/lib/RetailCrm/Methods/V5/Module.php b/lib/RetailCrm/Methods/V5/Module.php index 5322d08..421e02d 100644 --- a/lib/RetailCrm/Methods/V5/Module.php +++ b/lib/RetailCrm/Methods/V5/Module.php @@ -73,4 +73,32 @@ trait Module ['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 (!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)] + ); + } } From a95ec22823f27936af1ae074c402aec077a85310 Mon Sep 17 00:00:00 2001 From: Vladimir Kolchin Date: Fri, 20 Jan 2023 08:40:15 +0100 Subject: [PATCH 2/3] check code parameter in update-scopes method --- lib/RetailCrm/Methods/V5/Module.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/RetailCrm/Methods/V5/Module.php b/lib/RetailCrm/Methods/V5/Module.php index 421e02d..6ca8893 100644 --- a/lib/RetailCrm/Methods/V5/Module.php +++ b/lib/RetailCrm/Methods/V5/Module.php @@ -88,6 +88,12 @@ trait Module */ 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' From 069987b32d8166588932abfe8f89b0cfe8c4ae0d Mon Sep 17 00:00:00 2001 From: Vladimir Kolchin Date: Fri, 20 Jan 2023 10:37:23 +0100 Subject: [PATCH 3/3] add test for update-scopes method --- .../Methods/Version5/ApiClientModuleTest.php | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 tests/RetailCrm/Tests/Methods/Version5/ApiClientModuleTest.php diff --git a/tests/RetailCrm/Tests/Methods/Version5/ApiClientModuleTest.php b/tests/RetailCrm/Tests/Methods/Version5/ApiClientModuleTest.php new file mode 100644 index 0000000..5cd7a34 --- /dev/null +++ b/tests/RetailCrm/Tests/Methods/Version5/ApiClientModuleTest.php @@ -0,0 +1,60 @@ +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']); + } +}