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 Apr 3, 2024
1 parent 106cb65 commit ab3b35b
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/ApiPlatform/Resources/CustomerGroup.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
Expand Down Expand Up @@ -66,6 +65,7 @@
],
// Here, we use command mapping to adapt the normalized command result for the CQRS query
CQRSCommandMapping: [
'[_context][shopIds]' => '[shopIds]',
'[groupId]' => '[customerGroupId]',
],
),
Expand Down
41 changes: 40 additions & 1 deletion tests/Integration/ApiPlatform/CustomerGroupApiTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
Expand Down Expand Up @@ -105,6 +104,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 ab3b35b

Please sign in to comment.