Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to api-platform v3 #10

Merged
merged 1 commit into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ApiPlatform/Resources/ApiAccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

namespace PrestaShop\Module\APIResources\ApiPlatform\Resources;

use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Get;
Expand Down
2 changes: 1 addition & 1 deletion src/ApiPlatform/Resources/CustomerGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

namespace PrestaShop\Module\APIResources\ApiPlatform\Resources;

use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\Customer\Group\Command\AddCustomerGroupCommand;
use PrestaShop\PrestaShop\Core\Domain\Customer\Group\Command\DeleteCustomerGroupCommand;
Expand Down
2 changes: 1 addition & 1 deletion src/ApiPlatform/Resources/FoundProduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

namespace PrestaShop\Module\APIResources\ApiPlatform\Resources;

use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\GetCollection;
use PrestaShop\PrestaShop\Core\Domain\Product\Query\SearchProducts;
Expand Down
2 changes: 1 addition & 1 deletion src/ApiPlatform/Resources/Hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

namespace PrestaShop\Module\APIResources\ApiPlatform\Resources;

use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\Put;
Expand Down
2 changes: 1 addition & 1 deletion src/ApiPlatform/Resources/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

namespace PrestaShop\Module\APIResources\ApiPlatform\Resources;

use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\Product\Command\AddProductCommand;
use PrestaShop\PrestaShop\Core\Domain\Product\Command\DeleteProductCommand;
Expand Down
11 changes: 10 additions & 1 deletion tests/Integration/ApiPlatform/ApiTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ protected static function createClient(array $kernelOptions = [], array $default
$defaultOptions['headers']['accept'] = ['application/json'];
}

if (!isset($defaultOptions['headers']['content-type'])) {
$defaultOptions['headers']['content-type'] = ['application/json'];
}

return parent::createClient($kernelOptions, $defaultOptions);
}

Expand All @@ -77,7 +81,12 @@ protected function getBearerToken(array $scopes = []): string
'grant_type' => 'client_credentials',
'scope' => $scopes,
]];
$options = ['extra' => $parameters];
$options = [
'extra' => $parameters,
'headers' => [
'content-type' => 'application/x-www-form-urlencoded',
],
];
$response = $client->request('POST', '/api/oauth2/token', $options);

return json_decode($response->getContent())->access_token;
Expand Down
12 changes: 10 additions & 2 deletions tests/Integration/ApiPlatform/ProductEndpointTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,11 @@ public static function tearDownAfterClass(): void
* @param string $method
* @param string $uri
*/
public function testProtectedEndpoints(string $method, string $uri): void
public function testProtectedEndpoints(string $method, string $uri, string $contentType = 'application/json'): void
{
$options['headers']['content-type'] = $contentType;
// Check that endpoints are not accessible without a proper Bearer token
$client = static::createClient();
$client = static::createClient([], $options);
$response = $client->request($method, $uri);
self::assertResponseStatusCodeSame(401);

Expand Down Expand Up @@ -98,6 +99,7 @@ public function getProtectedEndpoints(): iterable
yield 'update endpoint' => [
'PATCH',
'/api/product/1',
'application/merge-patch+json',
];
}

Expand Down Expand Up @@ -160,6 +162,9 @@ public function testPartialUpdateProduct(int $productId): int
// Update product with partial data, even multilang fields can be updated language by language
$response = $client->request('PATCH', '/api/product/' . $productId, [
'auth_bearer' => $bearerToken,
'headers' => [
'content-type' => 'application/merge-patch+json',
],
'json' => [
'names' => [
self::$frenchLangId => 'nouveau nom',
Expand Down Expand Up @@ -197,6 +202,9 @@ public function testPartialUpdateProduct(int $productId): int
// Update product with partial data, only name default language the other names are not impacted
$response = $client->request('PATCH', '/api/product/' . $productId, [
'auth_bearer' => $bearerToken,
'headers' => [
'content-type' => 'application/merge-patch+json',
],
'json' => [
'names' => [
self::EN_LANG_ID => 'new product name',
Expand Down
Loading