diff --git a/src/ApiPlatform/Resources/Hook.php b/src/ApiPlatform/Resources/Hook.php index 430ccb6..52fc8de 100644 --- a/src/ApiPlatform/Resources/Hook.php +++ b/src/ApiPlatform/Resources/Hook.php @@ -25,51 +25,16 @@ use ApiPlatform\Metadata\ApiProperty; use ApiPlatform\Metadata\ApiResource; -use PrestaShop\PrestaShop\Core\Domain\Hook\Command\UpdateHookStatusCommand; use PrestaShop\PrestaShop\Core\Domain\Hook\Exception\HookNotFoundException; use PrestaShop\PrestaShop\Core\Domain\Hook\Query\GetHook; -use PrestaShop\PrestaShop\Core\Domain\Hook\Query\GetHookStatus; use PrestaShopBundle\ApiPlatform\Metadata\CQRSGet; -use PrestaShopBundle\ApiPlatform\Metadata\CQRSUpdate; use PrestaShopBundle\ApiPlatform\Metadata\PaginatedList; use PrestaShopBundle\ApiPlatform\Provider\QueryListProvider; #[ApiResource( operations: [ new CQRSGet( - uriTemplate: '/hook-status/{id}', - requirements: ['id' => '\d+'], - openapiContext: [ - 'summary' => 'Get hook status A', - 'description' => 'Get hook status B', - 'parameters' => [ - [ - 'name' => 'id', - 'in' => 'path', - 'required' => true, - 'schema' => [ - 'type' => 'string', - ], - 'description' => 'Id of the hook you are requesting the status from', - ], - [ - 'name' => 'Authorization', - 'in' => 'scopes', - 'description' => 'hook_read
hook_write ', - ], - ], - ], - exceptionToStatus: [HookNotFoundException::class => 404], - CQRSQuery: GetHookStatus::class, - scopes: ['hook_read'] - ), - new CQRSUpdate( - uriTemplate: '/hook-status', - CQRSCommand: UpdateHookStatusCommand::class, - scopes: ['hook_write'] - ), - new CQRSGet( - uriTemplate: '/hooks/{id}', + uriTemplate: '/hook/{id}', requirements: ['id' => '\d+'], exceptionToStatus: [HookNotFoundException::class => 404], CQRSQuery: GetHook::class, diff --git a/tests/Integration/ApiPlatform/GetHookStatusTest.php b/tests/Integration/ApiPlatform/GetHookStatusTest.php deleted file mode 100644 index 3588248..0000000 --- a/tests/Integration/ApiPlatform/GetHookStatusTest.php +++ /dev/null @@ -1,132 +0,0 @@ - - * @copyright Since 2007 PrestaShop SA and Contributors - * @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0 - */ - -declare(strict_types=1); - -namespace PsApiResourcesTest\Integration\ApiPlatform; - -use Tests\Resources\DatabaseDump; - -class GetHookStatusTest extends ApiTestCase -{ - public static function setUpBeforeClass(): void - { - parent::setUpBeforeClass(); - DatabaseDump::restoreTables(['hook']); - self::createApiClient(['hook_write', 'hook_read']); - } - - public static function tearDownAfterClass(): void - { - parent::tearDownAfterClass(); - DatabaseDump::restoreTables(['hook']); - } - - public function getProtectedEndpoints(): iterable - { - yield 'get endpoint' => [ - 'GET', - '/hook-status/1', - ]; - - yield 'put endpoint' => [ - 'PUT', - '/hook-status', - ]; - } - - public function testGetHookStatus(): void - { - $inactiveHook = new \Hook(); - $inactiveHook->name = 'inactiveHook'; - $inactiveHook->active = false; - $inactiveHook->add(); - - $activeHook = new \Hook(); - $activeHook->name = 'activeHook'; - $activeHook->active = true; - $activeHook->add(); - - $bearerToken = $this->getBearerToken([ - 'hook_read', - 'hook_write', - ]); - $response = static::createClient()->request('GET', '/hook-status/' . (int) $inactiveHook->id, ['auth_bearer' => $bearerToken]); - self::assertEquals(json_decode($response->getContent())->active, $inactiveHook->active); - self::assertResponseStatusCodeSame(200); - - $response = static::createClient()->request('GET', '/hook-status/' . (int) $activeHook->id, ['auth_bearer' => $bearerToken]); - self::assertEquals(json_decode($response->getContent())->active, $activeHook->active); - self::assertResponseStatusCodeSame(200); - - static::createClient()->request('GET', '/hook-status/' . 9999, ['auth_bearer' => $bearerToken]); - self::assertResponseStatusCodeSame(404); - - static::createClient()->request('GET', '/hook-status/' . $activeHook->id); - self::assertResponseStatusCodeSame(401); - - $inactiveHook->delete(); - $activeHook->delete(); - } - - public function testDisableHook(): void - { - $hook = new \Hook(); - $hook->name = 'disableHook'; - $hook->active = true; - $hook->add(); - - $bearerToken = $this->getBearerToken([ - 'hook_read', - 'hook_write', - ]); - static::createClient()->request('PUT', '/hook-status', [ - 'auth_bearer' => $bearerToken, - 'json' => ['id' => (int) $hook->id, 'active' => false], - ]); - self::assertResponseStatusCodeSame(200); - - $response = static::createClient()->request('GET', '/hook-status/' . (int) $hook->id, ['auth_bearer' => $bearerToken]); - self::assertEquals(json_decode($response->getContent())->active, false); - self::assertResponseStatusCodeSame(200); - } - - public function testEnableHook(): void - { - $hook = new \Hook(); - $hook->name = 'enableHook'; - $hook->active = false; - $hook->add(); - - $bearerToken = $this->getBearerToken([ - 'hook_read', - 'hook_write', - ]); - static::createClient()->request('PUT', '/hook-status', [ - 'auth_bearer' => $bearerToken, - 'json' => ['id' => (int) $hook->id, 'active' => true], - ]); - self::assertResponseStatusCodeSame(200); - - $response = static::createClient()->request('GET', '/hook-status/' . (int) $hook->id, ['auth_bearer' => $bearerToken]); - self::assertEquals(json_decode($response->getContent())->active, true); - self::assertResponseStatusCodeSame(200); - } -} diff --git a/tests/Integration/ApiPlatform/GetHookTest.php b/tests/Integration/ApiPlatform/GetHookTest.php index 5d3bde8..418382f 100644 --- a/tests/Integration/ApiPlatform/GetHookTest.php +++ b/tests/Integration/ApiPlatform/GetHookTest.php @@ -31,7 +31,7 @@ public static function setUpBeforeClass(): void { parent::setUpBeforeClass(); DatabaseDump::restoreTables(['hook']); - self::createApiClient(['hook_write', 'hook_read']); + self::createApiClient(['hook_read']); } public static function tearDownAfterClass(): void @@ -44,7 +44,7 @@ public function getProtectedEndpoints(): iterable { yield 'get endpoint' => [ 'GET', - '/hooks/1', + '/hook/1', ]; } @@ -57,17 +57,16 @@ public function testGetHook(): void $bearerToken = $this->getBearerToken([ 'hook_read', - 'hook_write', ]); - $response = static::createClient()->request('GET', '/hooks/' . (int) $hook->id, ['auth_bearer' => $bearerToken]); + $response = static::createClient()->request('GET', '/hook/' . (int) $hook->id, ['auth_bearer' => $bearerToken]); self::assertEquals(json_decode($response->getContent())->active, $hook->active); self::assertResponseStatusCodeSame(200); - static::createClient()->request('GET', '/hooks/' . 9999, ['auth_bearer' => $bearerToken]); + static::createClient()->request('GET', '/hook/' . 9999, ['auth_bearer' => $bearerToken]); self::assertResponseStatusCodeSame(404); - static::createClient()->request('GET', '/hooks/' . $hook->id); + static::createClient()->request('GET', '/hook/' . $hook->id); self::assertResponseStatusCodeSame(401); $hook->delete(); @@ -78,7 +77,6 @@ public function testListHooks(): void $hooks = $this->generateHooks(); $bearerToken = $this->getBearerToken([ 'hook_read', - 'hook_write', ]); $response = static::createClient()->request('GET', '/hooks', ['auth_bearer' => $bearerToken]);