Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/ApiPlatform/Resources/TaxRulesGroup/TaxRulesGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use PrestaShop\PrestaShop\Core\Domain\TaxRulesGroup\Command\AddTaxRulesGroupCommand;
use PrestaShop\PrestaShop\Core\Domain\TaxRulesGroup\Command\DeleteTaxRulesGroupCommand;
use PrestaShop\PrestaShop\Core\Domain\TaxRulesGroup\Command\EditTaxRulesGroupCommand;
use PrestaShop\PrestaShop\Core\Domain\TaxRulesGroup\Command\SetTaxRulesGroupStatusCommand;
use PrestaShop\PrestaShop\Core\Domain\TaxRulesGroup\Exception\CannotAddTaxRulesGroupException;
use PrestaShop\PrestaShop\Core\Domain\TaxRulesGroup\Exception\TaxRulesGroupNotFoundException;
use PrestaShop\PrestaShop\Core\Domain\TaxRulesGroup\Query\GetTaxRulesGroupForEditing;
Expand Down Expand Up @@ -70,6 +71,18 @@
CQRSQueryMapping: self::QUERY_MAPPING,
scopes: ['tax_rules_group_write'],
),
new CQRSPartialUpdate(
uriTemplate: '/tax-rules-groups/{taxRulesGroupId}/update-status',
requirements: ['taxRulesGroupId' => '\d+'],
output: false,
read: false,
CQRSCommand: SetTaxRulesGroupStatusCommand::class,
scopes: ['tax_rules_group_write'],
// No output 204 code
CQRSCommandMapping: [
'[enabled]' => '[expectedStatus]',
],
),
],
normalizationContext: ['skip_null_values' => false],
exceptionToStatus: [
Expand Down
53 changes: 53 additions & 0 deletions tests/Integration/ApiPlatform/TaxRulesGroupEndpointTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ public static function getProtectedEndpoints(): iterable
'PUT',
'/tax-rules-groups/bulk-update-status',
];

yield 'toggle status endpoint' => [
'PATCH',
'/tax-rules-groups/1/update-status',
];
}

public function testAddTaxRulesGroup(): int
Expand Down Expand Up @@ -187,6 +192,54 @@ public function testGetUpdatedTaxRulesGroup(int $taxRulesGroupId): int
return $taxRulesGroupId;
}

/**
* @depends testGetTaxRulesGroup
*
* @param int $taxRulesGroupId
*
* @return int
*/
public function testToggleTaxRulesGroupStatus(int $taxRulesGroupId): void
{
$response = $this->partialUpdateItem(
'/tax-rules-groups/' . $taxRulesGroupId . '/update-status',
['enabled' => false],
['tax_rules_group_write'],
Response::HTTP_NO_CONTENT
);
$this->assertNull($response);

$taxRulesGroup = $this->getItem('/tax-rules-groups/' . $taxRulesGroupId, ['tax_rules_group_read']);
$this->assertEquals(
[
'taxRulesGroupId' => $taxRulesGroupId,
'name' => 'My Tax Rules Group updated',
'enabled' => false,
'shopIds' => [1],
],
$taxRulesGroup
);

$response = $this->partialUpdateItem(
'/tax-rules-groups/' . $taxRulesGroupId . '/update-status',
['enabled' => true],
['tax_rules_group_write'],
Response::HTTP_NO_CONTENT
);
$this->assertNull($response);

$taxRulesGroup = $this->getItem('/tax-rules-groups/' . $taxRulesGroupId, ['tax_rules_group_read']);
$this->assertEquals(
[
'taxRulesGroupId' => $taxRulesGroupId,
'name' => 'My Tax Rules Group updated',
'enabled' => true,
'shopIds' => [1],
],
$taxRulesGroup
);
}

/**
* @depends testGetUpdatedTaxRulesGroup
*
Expand Down
Loading