mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 17:10:53 +00:00
Merge branch '1.13' into 1.14
* 1.13: [API] Adjust adjustments contract tests after upmerge
This commit is contained in:
commit
7ff7e6858c
2 changed files with 53 additions and 96 deletions
|
|
@ -54,6 +54,7 @@ final class OrderItemsTest extends JsonApiTestCase
|
|||
/** @test */
|
||||
public function it_gets_order_item_adjustments(): void
|
||||
{
|
||||
$this->setUpDefaultGetHeaders();
|
||||
$this->loadFixturesFromFiles([
|
||||
'channel.yaml',
|
||||
'cart.yaml',
|
||||
|
|
@ -70,9 +71,55 @@ final class OrderItemsTest extends JsonApiTestCase
|
|||
uri: '/api/v2/shop/orders/token/items/' . $order->getItems()->first()->getId() . '/adjustments',
|
||||
server: self::CONTENT_TYPE_HEADER,
|
||||
);
|
||||
$response = $this->client->getResponse();
|
||||
|
||||
$this->assertResponse($response, 'shop/order_item/get_order_item_adjustments', Response::HTTP_OK);
|
||||
$this->requestGet(sprintf('/api/v2/shop/orders/token/items/%s/adjustments', $order->getItems()->first()->getId()));
|
||||
|
||||
$this->assertResponse($this->client->getResponse(), 'shop/order_item/get_order_item_adjustments');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_returns_nothing_if_a_user_tries_to_get_the_order_item_adjustments_of_another_user(): void
|
||||
{
|
||||
$this->setUpDefaultGetHeaders();
|
||||
$this->loadFixturesFromFiles([
|
||||
'channel.yaml',
|
||||
'cart.yaml',
|
||||
'country.yaml',
|
||||
'authentication/customer.yaml',
|
||||
'shipping_method.yaml',
|
||||
'payment_method.yaml',
|
||||
'cart/promotion.yaml',
|
||||
]);
|
||||
|
||||
$order = $this->placeOrder('token', 'oliver@doe.com');
|
||||
|
||||
$this->requestGet(
|
||||
uri: '/api/v2/shop/orders/token/items/'.$order->getItems()->first()->getId().'/adjustments',
|
||||
headers: $this->headerBuilder()->withShopUserAuthorization('dave@doe.com')->build(),
|
||||
);
|
||||
|
||||
$this->assertResponseCode($this->client->getResponse(), Response::HTTP_FORBIDDEN);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_prevents_visitors_from_getting_the_item_adjustments_of_a_user_order(): void
|
||||
{
|
||||
$this->setUpDefaultGetHeaders();
|
||||
$this->loadFixturesFromFiles([
|
||||
'channel.yaml',
|
||||
'cart.yaml',
|
||||
'country.yaml',
|
||||
'authentication/customer.yaml',
|
||||
'shipping_method.yaml',
|
||||
'payment_method.yaml',
|
||||
'cart/promotion.yaml',
|
||||
]);
|
||||
|
||||
$order = $this->placeOrder('token', 'oliver@doe.com');
|
||||
|
||||
$this->requestGet(sprintf('/api/v2/shop/orders/token/items/%s/adjustments', $order->getItems()->first()->getId()));
|
||||
|
||||
$this->assertResponseCode($this->client->getResponse(), Response::HTTP_UNAUTHORIZED);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
|
|
@ -94,8 +141,7 @@ final class OrderItemsTest extends JsonApiTestCase
|
|||
uri: '/api/v2/shop/orders/WRONG_TOKEN/items/' . $order->getItems()->first()->getId() . '/adjustments',
|
||||
server: self::CONTENT_TYPE_HEADER,
|
||||
);
|
||||
$response = $this->client->getResponse();
|
||||
|
||||
$this->assertResponse($response, 'shop/order_item/get_empty_order_item_adjustments', Response::HTTP_OK);
|
||||
$this->assertResponseCode($this->client->getResponse(), Response::HTTP_UNAUTHORIZED);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,8 +13,6 @@ declare(strict_types=1);
|
|||
|
||||
namespace Sylius\Tests\Api\Shop;
|
||||
|
||||
use Sylius\Component\Core\Model\AdjustmentInterface;
|
||||
use Sylius\Component\Core\Model\OrderInterface;
|
||||
use Sylius\Component\Core\Model\PaymentMethodInterface;
|
||||
use Sylius\Tests\Api\JsonApiTestCase;
|
||||
use Sylius\Tests\Api\Utils\OrderPlacerTrait;
|
||||
|
|
@ -160,6 +158,7 @@ final class OrdersTest extends JsonApiTestCase
|
|||
/** @test */
|
||||
public function it_prevents_visitors_from_getting_the_adjustments_of_a_user_order(): void
|
||||
{
|
||||
$this->setUpDefaultGetHeaders();
|
||||
$this->loadFixturesFromFiles([
|
||||
'channel.yaml',
|
||||
'cart.yaml',
|
||||
|
|
@ -172,73 +171,9 @@ final class OrdersTest extends JsonApiTestCase
|
|||
$tokenValue = 'nAWw2jewpA';
|
||||
$this->placeOrder($tokenValue, 'oliver@doe.com');
|
||||
|
||||
$this->client->request('GET', '/api/v2/shop/orders/nAWw2jewpA/adjustments', [], [], self::CONTENT_TYPE_HEADER);
|
||||
$response = $this->client->getResponse();
|
||||
$this->requestGet(sprintf('/api/v2/shop/orders/%s/adjustments', $tokenValue));
|
||||
|
||||
$this->assertResponseCode($response, Response::HTTP_UNAUTHORIZED);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_prevents_visitors_from_getting_the_item_adjustments_of_a_user_order(): void
|
||||
{
|
||||
$this->loadFixturesFromFiles([
|
||||
'channel.yaml',
|
||||
'cart.yaml',
|
||||
'country.yaml',
|
||||
'authentication/customer.yaml',
|
||||
'shipping_method.yaml',
|
||||
'payment_method.yaml',
|
||||
]);
|
||||
|
||||
$tokenValue = $this->pickUpCart();
|
||||
|
||||
$order = $this->createOrderWithOrderItemAdjustments($tokenValue, 'oliver@doe.com');
|
||||
|
||||
$this->client->request('GET', '/api/v2/shop/orders/nAWw2jewpA/items/'.$order->getItems()->first()->getId().'/adjustments', [], [], self::CONTENT_TYPE_HEADER);
|
||||
$response = $this->client->getResponse();
|
||||
|
||||
$this->assertResponseCode($response, Response::HTTP_UNAUTHORIZED);
|
||||
}
|
||||
|
||||
public function it_returns_nothing_if_a_user_tries_to_get_the_order_item_adjustments_of_another_user(): void
|
||||
{
|
||||
$this->loadFixturesFromFiles([
|
||||
'channel.yaml',
|
||||
'cart.yaml',
|
||||
'country.yaml',
|
||||
'authentication/customer.yaml',
|
||||
'shipping_method.yaml',
|
||||
'payment_method.yaml',
|
||||
]);
|
||||
|
||||
$loginData = $this->logInShopUser('dave@doe.com');
|
||||
$authorizationHeader = self::$kernel->getContainer()->getParameter('sylius.api.authorization_header');
|
||||
$header['HTTP_' . $authorizationHeader] = 'Bearer ' . $loginData;
|
||||
$header = array_merge($header, self::CONTENT_TYPE_HEADER);
|
||||
|
||||
$tokenValue = $this->pickUpCart();
|
||||
|
||||
$order = $this->createOrderWithOrderItemAdjustments($tokenValue, 'oliver@doe.com');
|
||||
|
||||
$this->client->request('GET', '/api/v2/shop/orders/nAWw2jewpA/items/'.$order->getItems()->first()->getId().'/adjustments', [], [], $header);
|
||||
$response = $this->client->getResponse();
|
||||
|
||||
$this->assertResponseCode($response, Response::HTTP_UNAUTHORIZED);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_gets_order_item_adjustments(): void
|
||||
{
|
||||
$this->loadFixturesFromFiles(['channel.yaml', 'cart.yaml', 'country.yaml', 'shipping_method.yaml', 'payment_method.yaml']);
|
||||
|
||||
$tokenValue = $this->pickUpCart();
|
||||
|
||||
$order = $this->createOrderWithOrderItemAdjustments($tokenValue);
|
||||
|
||||
$this->client->request('GET', '/api/v2/shop/orders/nAWw2jewpA/items/'.$order->getItems()->first()->getId().'/adjustments', [], [], self::CONTENT_TYPE_HEADER);
|
||||
$response = $this->client->getResponse();
|
||||
|
||||
$this->assertResponse($response, 'shop/get_order_item_adjustments_response', Response::HTTP_OK);
|
||||
$this->assertResponseCode($this->client->getResponse(), Response::HTTP_UNAUTHORIZED);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
|
|
@ -368,28 +303,4 @@ final class OrdersTest extends JsonApiTestCase
|
|||
|
||||
$this->assertResponseCode($this->client->getResponse(), Response::HTTP_NOT_FOUND);
|
||||
}
|
||||
|
||||
private function createOrderWithOrderItemAdjustments(string $tokenValue, string $email = 'sylius@example.com'): OrderInterface
|
||||
{
|
||||
$this->addItemToCart('MUG_BLUE', 3, $tokenValue);
|
||||
|
||||
/** @var OrderInterface $order */
|
||||
$order = $this->get('sylius.repository.order')->findCartByTokenValue($tokenValue);
|
||||
$orderItem = $order->getItems()->first();
|
||||
|
||||
/** @var AdjustmentInterface $adjustment */
|
||||
$adjustment = $this->get('sylius.factory.adjustment')->createNew();
|
||||
|
||||
$adjustment->setType(AdjustmentInterface::ORDER_ITEM_PROMOTION_ADJUSTMENT);
|
||||
$adjustment->setAmount(200);
|
||||
$adjustment->setNeutral(false);
|
||||
$adjustment->setLabel('Test Promotion Adjustment');
|
||||
|
||||
$this->updateCartWithAddress($tokenValue, $email);
|
||||
|
||||
$orderItem->addAdjustment($adjustment);
|
||||
$this->get('sylius.manager.order')->flush();
|
||||
|
||||
return $order;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue