Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 80231af

Browse files
committed
POST and item GET
1 parent 3fafeca commit 80231af

2 files changed

Lines changed: 56 additions & 2 deletions

File tree

tests/Api/Admin/CatalogPromotionsTest.php

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function it_allows_admin_to_get_catalog_promotions(): void
3333

3434
$this->client->request(
3535
'GET',
36-
sprintf('/api/v2/admin/catalog-promotions'),
36+
'/api/v2/admin/catalog-promotions',
3737
[],
3838
[],
3939
$header
@@ -44,6 +44,53 @@ public function it_allows_admin_to_get_catalog_promotions(): void
4444
$this->assertResponse($response, 'admin/get_catalog_promotions_admin_response', Response::HTTP_OK);
4545
}
4646

47+
/** @test */
48+
public function it_allows_admin_to_get_catalog_promotion(): void
49+
{
50+
$catalogPromotion = $this->loadFixturesFromFiles(['authentication/api_administrator.yaml', 'catalog_promotion.yaml'])['catalog_promotion'];
51+
52+
$token = $this->logInAdminUser('[email protected]');
53+
$authorizationHeader = self::$container->getParameter('sylius.api.authorization_header');
54+
$header['HTTP_' . $authorizationHeader] = 'Bearer ' . $token;
55+
$header = array_merge($header, self::CONTENT_TYPE_HEADER);
56+
57+
$this->client->request(
58+
'GET',
59+
sprintf('/api/v2/admin/catalog-promotions/%s', $catalogPromotion['id']),
60+
[],
61+
[],
62+
$header
63+
);
64+
65+
$response = $this->client->getResponse();
66+
67+
$this->assertResponse($response, 'admin/get_catalog_promotion_admin_response', Response::HTTP_OK);
68+
}
69+
70+
/** @test */
71+
public function it_allows_admin_to_post_new_catalog_promotion(): void
72+
{
73+
$this->loadFixturesFromFiles(['authentication/api_administrator.yaml', 'catalog_promotion.yaml']);
74+
75+
$token = $this->logInAdminUser('[email protected]');
76+
$authorizationHeader = self::$container->getParameter('sylius.api.authorization_header');
77+
$header['HTTP_' . $authorizationHeader] = 'Bearer ' . $token;
78+
$header = array_merge($header, self::CONTENT_TYPE_HEADER);
79+
80+
$this->client->request(
81+
'POST',
82+
'/api/v2/admin/catalog-promotions',
83+
[],
84+
[],
85+
$header,
86+
json_encode(["name" => "new_promotion", "code" => "new_code"], JSON_THROW_ON_ERROR)
87+
);
88+
89+
$response = $this->client->getResponse();
90+
91+
$this->assertResponseCode($response, Response::HTTP_CREATED);
92+
}
93+
4794
/** @test */
4895
public function it_allows_admin_to_update_catalog_promotion(): void
4996
{
@@ -103,7 +150,7 @@ private function getId(array $header): string
103150
{
104151
$this->client->request(
105152
'GET',
106-
sprintf('/api/v2/admin/catalog-promotions'),
153+
'/api/v2/admin/catalog-promotions',
107154
[],
108155
[],
109156
$header
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"@id": "\/api\/v2\/admin\/catalog-promotions\/@integer@",
3+
"@type": "CatalogPromotion",
4+
"id": "@integer@",
5+
"name": "catalog promotion",
6+
"code": "catalog_promotion"
7+
}

0 commit comments

Comments
 (0)