Skip to content

Commit

Permalink
chore(api) modify customer group endpoint mapping and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tleon committed Mar 28, 2024
1 parent fd1eca6 commit 0c34a5c
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 6 deletions.
13 changes: 10 additions & 3 deletions src/ApiPlatform/Resources/CustomerGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,23 @@
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* 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/AFL-3.0
* 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/AFL-3.0 Academic Free License version 3.0
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
*/

declare(strict_types=1);
Expand Down Expand Up @@ -66,6 +72,7 @@
],
// Here, we use command mapping to adapt the normalized command result for the CQRS query
CQRSCommandMapping: [
'[_context][shopIds]' => '[shopIds]',
'[groupId]' => '[customerGroupId]',
],
),
Expand Down
52 changes: 49 additions & 3 deletions tests/Integration/ApiPlatform/CustomerGroupApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,23 @@
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* 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/AFL-3.0
* 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/AFL-3.0 Academic Free License version 3.0
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
*/

declare(strict_types=1);
Expand Down Expand Up @@ -105,6 +111,46 @@ public function testAddCustomerGroup(): int
return $customerGroupId;
}

public function testAddCustomerGroupWithoutShopIds(): int
{
$numberOfGroups = count(\Group::getGroups(\Context::getContext()->language->id));

$bearerToken = $this->getBearerToken(['customer_group_write']);
$response = static::createClient()->request('POST', '/customers/group', [
'auth_bearer' => $bearerToken,
'json' => [
'localizedNames' => [
1 => 'test1',
],
'reductionPercent' => 10.3,
'displayPriceTaxExcluded' => true,
'showPrice' => true,
],
]);
self::assertResponseStatusCodeSame(201);
self::assertCount($numberOfGroups + 1, \Group::getGroups(\Context::getContext()->language->id));

$decodedResponse = json_decode($response->getContent(), true);
$this->assertNotFalse($decodedResponse);
$this->assertArrayHasKey('customerGroupId', $decodedResponse);
$customerGroupId = $decodedResponse['customerGroupId'];
$this->assertEquals(
[
'customerGroupId' => $customerGroupId,
'localizedNames' => [
1 => 'test1',
],
'reductionPercent' => 10.3,
'displayPriceTaxExcluded' => true,
'showPrice' => true,
'shopIds' => [1],
],
$decodedResponse
);

return $customerGroupId;
}

/**
* @depends testAddCustomerGroup
*
Expand Down

0 comments on commit 0c34a5c

Please sign in to comment.