Skip to content

Commit 7b7a7fd

Browse files
committed
Fix review
1 parent 3f30d9d commit 7b7a7fd

File tree

2 files changed

+76
-5
lines changed

2 files changed

+76
-5
lines changed

src/ApiPlatform/Resources/Discount/DiscountType.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@
3131
new CQRSGetCollection(
3232
uriTemplate: '/discount-types',
3333
CQRSQuery: GetDiscountTypes::class,
34-
scopes: [],
34+
scopes: ['discount_read'],
3535
CQRSQueryMapping: [],
3636
ApiResourceMapping: [
3737
'[type]' => '[type]',
3838
'[localizedNames]' => '[names]',
3939
'[localizedDescriptions]' => '[descriptions]',
40-
'[isCore]' => '[isCore]',
41-
'[active]' => '[active]',
40+
'[core]' => '[core]',
41+
'[enabled]' => '[enabled]',
4242
],
4343
),
4444
],
@@ -57,7 +57,7 @@ class DiscountType
5757
#[LocalizedValue]
5858
public array $descriptions;
5959

60-
public bool $isCore;
60+
public bool $core;
6161

62-
public bool $active;
62+
public bool $enabled;
6363
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
/**
3+
* Copyright since 2007 PrestaShop SA and Contributors
4+
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
5+
*
6+
* NOTICE OF LICENSE
7+
*
8+
* This source file is subject to the Academic Free License version 3.0
9+
* that is bundled with this package in the file LICENSE.md.
10+
* It is also available through the world-wide-web at this URL:
11+
* https://opensource.org/licenses/AFL-3.0
12+
* If you did not receive a copy of the license and are unable to
13+
* obtain it through the world-wide-web, please send an email
14+
* to license@prestashop.com so we can send you a copy immediately.
15+
*
16+
* @author PrestaShop SA and Contributors <contact@prestashop.com>
17+
* @copyright Since 2007 PrestaShop SA and Contributors
18+
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
19+
*/
20+
21+
namespace PsApiResourcesTest\Integration\ApiPlatform;
22+
23+
class DiscountTypeEndpointTest extends ApiTestCase
24+
{
25+
public static function setUpBeforeClass(): void
26+
{
27+
parent::setUpBeforeClass();
28+
self::createApiClient();
29+
}
30+
31+
public static function getProtectedEndpoints(): iterable
32+
{
33+
// The endpoint doesn't require any scope but you still need to be logged (have a valid token)
34+
yield 'get endpoint' => [
35+
'GET',
36+
'/discount-types',
37+
];
38+
}
39+
40+
public function testGetDiscountTypes(): void
41+
{
42+
$discountTypes = $this->listDiscountTypes();
43+
44+
$this->assertGreaterThanOrEqual(1, count($discountTypes));
45+
46+
if (count($discountTypes) > 0) {
47+
$firstType = $discountTypes[0];
48+
$this->assertArrayHasKey('discountTypeId', $firstType);
49+
$this->assertArrayHasKey('type', $firstType);
50+
$this->assertArrayHasKey('names', $firstType);
51+
$this->assertArrayHasKey('descriptions', $firstType);
52+
$this->assertArrayHasKey('isCore', $firstType);
53+
$this->assertArrayHasKey('active', $firstType);
54+
}
55+
}
56+
57+
private function listDiscountTypes(): array
58+
{
59+
$bearerToken = $this->getBearerToken();
60+
$response = static::createClient()->request('GET', '/discount-types', [
61+
'auth_bearer' => $bearerToken,
62+
]);
63+
self::assertResponseStatusCodeSame(200);
64+
65+
$decodedResponse = json_decode($response->getContent(), true);
66+
$this->assertNotFalse($decodedResponse);
67+
$this->assertIsArray($decodedResponse);
68+
69+
return $decodedResponse;
70+
}
71+
}

0 commit comments

Comments
 (0)