Skip to content

Commit

Permalink
chore(ci): move tests and endpoint from core
Browse files Browse the repository at this point in the history
  • Loading branch information
tleon committed Jan 24, 2024
1 parent f427ce2 commit e42236a
Show file tree
Hide file tree
Showing 10 changed files with 1,595 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@ jobs:
USER_ID=$(id -u) GROUP_ID=$(id -g) docker exec prestashop_prestashop-git_1 composer create-test-db
- name: Run integration tests
run : |
USER_ID=$(id -u) GROUP_ID=$(id -g) docker exec prestashop_prestashop-git_1 ls ../../../../
USER_ID=$(id -u) GROUP_ID=$(id -g) docker exec prestashop_prestashop-git_1 vendor/bin/phpunit -c modules/ps_apiresources/tests/Integration/phpunit.xml
76 changes: 76 additions & 0 deletions src/ApiPlatform/Resources/CartRule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://devdocs.prestashop.com/ for more information.
*
* @author PrestaShop SA and Contributors <[email protected]>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
*/

declare(strict_types=1);

namespace PrestaShop\Module\APIResources\ApiPlatform\Resources;

use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Put;
use PrestaShop\PrestaShop\Core\Domain\CartRule\Command\EditCartRuleCommand;
use PrestaShopBundle\ApiPlatform\Processor\CommandProcessor;

#[ApiResource(
operations: [
new Put(
uriTemplate: '/cart-rule',
processor: CommandProcessor::class,
extraProperties: ['CQRSCommand' => EditCartRuleCommand::class]
),
],
)]
class CartRule
{
public int $cartRuleId;

public string $description;

public string $code;

public array $minimumAmount;

public bool $minimumAmountShippingIncluded;

public int $customerId;

public array $localizedNames;

public bool $highlightInCart;

public bool $allowPartialUse;

public int $priority;

public bool $active;

public array $validityDateRange;

public int $totalQuantity;

public int $quantityPerUser;

public array $cartRuleAction;
}
119 changes: 119 additions & 0 deletions src/ApiPlatform/Resources/CustomerGroup.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
<?php

/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://devdocs.prestashop.com/ for more information.
*
* @author PrestaShop SA and Contributors <[email protected]>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
*/

declare(strict_types=1);

namespace PrestaShop\Module\APIResources\ApiPlatform\Resources;

use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\Customer\Group\Command\AddCustomerGroupCommand;
use PrestaShop\PrestaShop\Core\Domain\Customer\Group\Command\DeleteCustomerGroupCommand;
use PrestaShop\PrestaShop\Core\Domain\Customer\Group\Command\EditCustomerGroupCommand;
use PrestaShop\PrestaShop\Core\Domain\Customer\Group\Exception\GroupNotFoundException;
use PrestaShop\PrestaShop\Core\Domain\Customer\Group\Query\GetCustomerGroupForEditing;
use PrestaShop\PrestaShop\Core\Domain\Customer\Group\QueryResult\EditableCustomerGroup;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSCreate;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSDelete;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSGet;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSUpdate;

#[ApiResource(
operations: [
new CQRSGet(
uriTemplate: '/customers/group/{customerGroupId}',
CQRSQuery: GetCustomerGroupForEditing::class,
scopes: [
'customer_group_read',
],
// QueryResult format doesn't match with ApiResource, so we can specify a mapping so that it is normalized with extra fields adapted for the ApiResource DTO
CQRSQueryMapping: [
// EditableCustomerGroup::$id is normalized as [customerGroupId]
'[id]' => '[customerGroupId]',
// EditableCustomerGroup::$reduction is normalized as [reductionPercent]
'[reduction]' => '[reductionPercent]',
],
),
new CQRSCreate(
uriTemplate: '/customers/group',
CQRSCommand: AddCustomerGroupCommand::class,
CQRSQuery: GetCustomerGroupForEditing::class,
scopes: [
'customer_group_write',
],
// Here, we use query mapping to adapt normalized query result for the ApiPlatform DTO
CQRSQueryMapping: [
'[id]' => '[customerGroupId]',
'[reduction]' => '[reductionPercent]',
],
// Here, we use command mapping to adapt the normalized command result for the CQRS query
CQRSCommandMapping: [
'[groupId]' => '[customerGroupId]',
],
),
new CQRSUpdate(
uriTemplate: '/customers/group/{customerGroupId}',
CQRSCommand: EditCustomerGroupCommand::class,
CQRSQuery: GetCustomerGroupForEditing::class,
scopes: [
'customer_group_write',
],
// Here we use the ApiResource DTO mapping to transform the normalized query result
ApiResourceMapping: [
'[id]' => '[customerGroupId]',
'[reduction]' => '[reductionPercent]',
],
),
new CQRSDelete(
uriTemplate: '/customers/group/{customerGroupId}',
CQRSQuery: DeleteCustomerGroupCommand::class,
scopes: [
'customer_group_write',
],
// Here, we use query mapping to adapt URI parameters to the expected constructor parameter name
CQRSQueryMapping: [
'[customerGroupId]' => '[groupId]',
],
),
],
exceptionToStatus: [GroupNotFoundException::class => 404],
)]
class CustomerGroup
{
#[ApiProperty(identifier: true)]
public int $customerGroupId;

public array $localizedNames;

public float $reductionPercent;

public bool $displayPriceTaxExcluded;

public bool $showPrice;

public array $shopIds;
}
108 changes: 108 additions & 0 deletions src/ApiPlatform/Resources/FoundProduct.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://devdocs.prestashop.com/ for more information.
*
* @author PrestaShop SA and Contributors <[email protected]>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
*/

declare(strict_types=1);

namespace PrestaShop\Module\APIResources\ApiPlatform\Resources;

use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\GetCollection;
use PrestaShop\PrestaShop\Core\Domain\Product\Query\SearchProducts;
use PrestaShopBundle\ApiPlatform\Provider\QueryProvider;

#[ApiResource(
operations: [
new GetCollection(
uriTemplate: '/products/search/{phrase}/{resultsLimit}/{isoCode}',
openapiContext: [
'parameters' => [
[
'name' => 'phrase',
'in' => 'path',
'required' => true,
'schema' => [
'type' => 'string',
],
],
[
'name' => 'resultsLimit',
'in' => 'path',
'required' => true,
'schema' => [
'type' => 'int',
],
],
[
'name' => 'isoCode',
'in' => 'path',
'required' => true,
'schema' => [
'type' => 'string',
],
],
[
'name' => 'orderId',
'in' => 'query',
'required' => false,
'schema' => [
'type' => 'int',
],
],
],
],
provider: QueryProvider::class,
extraProperties: [
'CQRSQuery' => SearchProducts::class,
]
),
],
)]
class FoundProduct
{
#[ApiProperty(identifier: true)]
public int $productId;

public bool $availableOutOfStock;

public string $name;

public float $taxRate;

public string $formattedPrice;

public float $priceTaxIncl;

public float $priceTaxExcl;

public int $stock;

public string $location;

public array $combinations;

public array $customizationFields;
}
Loading

0 comments on commit e42236a

Please sign in to comment.