Skip to content

Commit 1f61696

Browse files
Progi1984boherm
authored andcommitted
Added endpoints for domain "ShowcaseCard"
1 parent 0e57b9a commit 1f61696

File tree

3 files changed

+148
-1
lines changed

3 files changed

+148
-1
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,4 @@
5656
},
5757
"type": "prestashop-module",
5858
"author": "PrestaShop"
59-
}
59+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
/**
4+
* Copyright since 2007 PrestaShop SA and Contributors
5+
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
6+
*
7+
* NOTICE OF LICENSE
8+
*
9+
* This source file is subject to the Academic Free License version 3.0
10+
* that is bundled with this package in the file LICENSE.md.
11+
* It is also available through the world-wide-web at this URL:
12+
* https://opensource.org/licenses/AFL-3.0
13+
* If you did not receive a copy of the license and are unable to
14+
* obtain it through the world-wide-web, please send an email
15+
* to license@prestashop.com so we can send you a copy immediately.
16+
*
17+
* @author PrestaShop SA and Contributors <contact@prestashop.com>
18+
* @copyright Since 2007 PrestaShop SA and Contributors
19+
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
20+
*/
21+
22+
declare(strict_types=1);
23+
24+
namespace PrestaShop\Module\APIResources\ApiPlatform\Resources\ShowcaseCard;
25+
26+
use ApiPlatform\Metadata\ApiResource;
27+
use PrestaShop\PrestaShop\Core\Domain\ShowcaseCard\Command\CloseShowcaseCardCommand;
28+
use PrestaShop\PrestaShop\Core\Domain\ShowcaseCard\Query\GetShowcaseCardIsClosed;
29+
use PrestaShopBundle\ApiPlatform\Metadata\CQRSGet;
30+
use PrestaShopBundle\ApiPlatform\Metadata\CQRSUpdate;
31+
32+
#[ApiResource(
33+
operations: [
34+
new CQRSGet(
35+
uriTemplate: '/showcase-cards/{showcaseCardName}/{employeeId}',
36+
requirements: [
37+
'showcaseCardName' => '[a-z_-]+',
38+
'employeeId' => '\d+',
39+
],
40+
CQRSQuery: GetShowcaseCardIsClosed::class,
41+
CQRSQueryMapping: [
42+
'[_queryResult]' => '[closed]',
43+
],
44+
scopes: ['showcase_card_read'],
45+
),
46+
new CQRSUpdate(
47+
uriTemplate: '/showcase-cards/{showcaseCardName}/{employeeId}/close',
48+
requirements: [
49+
'showcaseCardName' => '[a-z_-]+',
50+
'employeeId' => '\d+',
51+
],
52+
allowEmptyBody: true,
53+
CQRSCommand: CloseShowcaseCardCommand::class,
54+
CQRSQuery: GetShowcaseCardIsClosed::class,
55+
CQRSQueryMapping: [
56+
'[_queryResult]' => '[closed]',
57+
],
58+
scopes: ['showcase_card_write'],
59+
),
60+
],
61+
)]
62+
class ShowcaseCard
63+
{
64+
public string $showcaseCardName;
65+
66+
public int $employeeId;
67+
68+
public bool $closed;
69+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
3+
/**
4+
* Copyright since 2007 PrestaShop SA and Contributors
5+
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
6+
*
7+
* NOTICE OF LICENSE
8+
*
9+
* This source file is subject to the Academic Free License version 3.0
10+
* that is bundled with this package in the file LICENSE.md.
11+
* It is also available through the world-wide-web at this URL:
12+
* https://opensource.org/licenses/AFL-3.0
13+
* If you did not receive a copy of the license and are unable to
14+
* obtain it through the world-wide-web, please send an email
15+
* to license@prestashop.com so we can send you a copy immediately.
16+
*
17+
* @author PrestaShop SA and Contributors <contact@prestashop.com>
18+
* @copyright Since 2007 PrestaShop SA and Contributors
19+
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
20+
*/
21+
22+
declare(strict_types=1);
23+
24+
namespace PsApiResourcesTest\Integration\ApiPlatform;
25+
26+
use Tests\Resources\DatabaseDump;
27+
28+
class ShowcaseCardEndpointTest extends ApiTestCase
29+
{
30+
protected const TEST_SHOWCASECARD = 'monitoring_card';
31+
protected const TEST_EMPLOYEE_ID = 1;
32+
33+
public static function setUpBeforeClass(): void
34+
{
35+
parent::setUpBeforeClass();
36+
self::createApiClient(['showcase_card_read', 'showcase_card_write']);
37+
}
38+
39+
public static function tearDownAfterClass(): void
40+
{
41+
parent::tearDownAfterClass();
42+
// Reset DB as it was before this test
43+
DatabaseDump::restoreTables(['configuration']);
44+
}
45+
46+
public static function getProtectedEndpoints(): iterable
47+
{
48+
yield 'get endpoint' => [
49+
'GET',
50+
'/showcase-cards/' . self::TEST_SHOWCASECARD . '/' . self::TEST_EMPLOYEE_ID,
51+
];
52+
yield 'put endpoint' => [
53+
'PUT',
54+
'/showcase-cards/' . self::TEST_SHOWCASECARD . '/' . self::TEST_EMPLOYEE_ID . '/close',
55+
];
56+
}
57+
58+
public function testGetShowcard(): void
59+
{
60+
$showcaseCard = $this->getItem('/showcase-cards/' . self::TEST_SHOWCASECARD . '/' . self::TEST_EMPLOYEE_ID, ['showcase_card_read']);
61+
62+
$this->assertEquals(self::TEST_SHOWCASECARD, $showcaseCard['showcaseCardName']);
63+
$this->assertEquals(self::TEST_EMPLOYEE_ID, $showcaseCard['employeeId']);
64+
$this->assertEquals(false, $showcaseCard['isClosed']);
65+
}
66+
67+
/**
68+
* @depends testGetShowcard
69+
*/
70+
public function testCloseShowcard(): void
71+
{
72+
$showcaseCard = $this->updateItem('/showcase-cards/' . self::TEST_SHOWCASECARD . '/' . self::TEST_EMPLOYEE_ID . '/close', null, ['showcase_card_write']);
73+
74+
$this->assertEquals(self::TEST_SHOWCASECARD, $showcaseCard['showcaseCardName']);
75+
$this->assertEquals(self::TEST_EMPLOYEE_ID, $showcaseCard['employeeId']);
76+
$this->assertEquals(true, $showcaseCard['isClosed']);
77+
}
78+
}

0 commit comments

Comments
 (0)