From 0c34a5c4655497eab5ba08fd468a9339cc4635d2 Mon Sep 17 00:00:00 2001 From: tleon Date: Thu, 28 Mar 2024 16:29:31 +0100 Subject: [PATCH] chore(api) modify customer group endpoint mapping and tests --- src/ApiPlatform/Resources/CustomerGroup.php | 13 +++-- .../ApiPlatform/CustomerGroupApiTest.php | 52 +++++++++++++++++-- 2 files changed, 59 insertions(+), 6 deletions(-) diff --git a/src/ApiPlatform/Resources/CustomerGroup.php b/src/ApiPlatform/Resources/CustomerGroup.php index 77ed229..629b35f 100644 --- a/src/ApiPlatform/Resources/CustomerGroup.php +++ b/src/ApiPlatform/Resources/CustomerGroup.php @@ -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 license@prestashop.com 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 * @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]', ], ), diff --git a/tests/Integration/ApiPlatform/CustomerGroupApiTest.php b/tests/Integration/ApiPlatform/CustomerGroupApiTest.php index 4c2d7ef..9d87e8b 100644 --- a/tests/Integration/ApiPlatform/CustomerGroupApiTest.php +++ b/tests/Integration/ApiPlatform/CustomerGroupApiTest.php @@ -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 license@prestashop.com 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 * @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 *