forked from PrestaShop/ps_apiresources
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(api) modify customer group endpoint mapping and tests
- Loading branch information
Showing
2 changed files
with
59 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
|
@@ -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]', | ||
], | ||
), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
|
@@ -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 | ||
* | ||
|