mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 09:02:12 +00:00
[API][Adjustment] Enable unit tests
This commit is contained in:
parent
1f4d7f81ed
commit
536bfa2a46
13 changed files with 175 additions and 136 deletions
|
|
@ -45,31 +45,4 @@ final class OrderItemUnitsTest extends JsonApiTestCase
|
|||
|
||||
$this->assertResponse($response, 'admin/order_item_units/get_order_item_unit_response', Response::HTTP_OK);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_gets_adjustments_for_an_order_item_unit(): void
|
||||
{
|
||||
$this->loadFixturesFromFiles([
|
||||
'authentication/api_administrator.yaml',
|
||||
'channel.yaml',
|
||||
'cart.yaml',
|
||||
'country.yaml',
|
||||
'shipping_method.yaml',
|
||||
'payment_method.yaml',
|
||||
'cart/promotion.yaml',
|
||||
]);
|
||||
|
||||
$order = $this->placeOrder('token');
|
||||
$orderItemUnit = $order->getItems()->first()->getUnits()->first();
|
||||
|
||||
$this->client->request(
|
||||
method: 'GET',
|
||||
uri: '/api/v2/admin/order-item-units/' . $orderItemUnit->getId() . '/adjustments',
|
||||
server: $this->headerBuilder()->withJsonLdAccept()->withAdminUserAuthorization('api@example.com')->build(),
|
||||
);
|
||||
|
||||
$response = $this->client->getResponse();
|
||||
|
||||
$this->assertResponse($response, 'admin/order_item_units/get_order_item_unit_adjustments', Response::HTTP_OK);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,34 +47,4 @@ final class OrderItemsTest extends JsonApiTestCase
|
|||
|
||||
$this->assertResponse($response, 'admin/order_item/get_order_item_response', Response::HTTP_OK);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_gets_adjustments_for_an_order_item(): void
|
||||
{
|
||||
$fixtures = $this->loadFixturesFromFiles([
|
||||
'authentication/api_administrator.yaml',
|
||||
'channel.yaml',
|
||||
'order/order_with_item.yaml',
|
||||
'country.yaml',
|
||||
'shipping_method.yaml',
|
||||
'payment_method.yaml',
|
||||
'product/product.yaml',
|
||||
'product/product_variant.yaml',
|
||||
'tax_category.yaml',
|
||||
'shipping_category.yaml',
|
||||
'customer.yaml',
|
||||
]);
|
||||
$orderItem = $fixtures['order_item'];
|
||||
$header = array_merge($this->logInAdminUser('api@example.com'), self::CONTENT_TYPE_HEADER);
|
||||
|
||||
$this->client->request(
|
||||
method: 'GET',
|
||||
uri: '/api/v2/admin/order-items/' . $orderItem->getId() . '/adjustments',
|
||||
server: $header,
|
||||
);
|
||||
|
||||
$response = $this->client->getResponse();
|
||||
|
||||
$this->assertResponse($response, 'admin/order_item/get_order_item_adjustments_response', Response::HTTP_OK);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -199,20 +199,6 @@ final class OrdersTest extends JsonApiTestCase
|
|||
$this->assertResponseSuccessful('admin/order/get_order_response');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_gets_adjustments_for_order(): void
|
||||
{
|
||||
$this->loadFixturesFromFiles(['authentication/api_administrator.yaml', 'channel.yaml', 'cart.yaml', 'country.yaml', 'shipping_method.yaml', 'payment_method.yaml']);
|
||||
|
||||
$tokenValue = 'nAWw2jewpA';
|
||||
|
||||
$this->placeOrder($tokenValue);
|
||||
|
||||
$this->requestGet(uri: '/api/v2/admin/orders/nAWw2jewpA/adjustments');
|
||||
|
||||
$this->assertResponseSuccessful('admin/order/get_adjustments_for_a_given_order_response');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_gets_a_billing_address_of_placed_order(): void
|
||||
{
|
||||
|
|
|
|||
|
|
@ -126,32 +126,6 @@ final class ShipmentsTest extends JsonApiTestCase
|
|||
$this->assertEmailCount(1);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_gets_adjustments_for_a_shipment(): void
|
||||
{
|
||||
$this->loadFixturesFromFiles([
|
||||
'authentication/api_administrator.yaml',
|
||||
'channel.yaml',
|
||||
'cart.yaml',
|
||||
'country.yaml',
|
||||
'shipping_method.yaml',
|
||||
'payment_method.yaml',
|
||||
]);
|
||||
|
||||
$order = $this->placeOrder('token');
|
||||
$shipment = $order->getShipments()->first();
|
||||
|
||||
$this->client->request(
|
||||
method: 'GET',
|
||||
uri: '/api/v2/admin/shipments/' . $shipment->getId() . '/adjustments',
|
||||
server: $this->buildHeadersWithJsonLd('api@example.com'),
|
||||
);
|
||||
|
||||
$response = $this->client->getResponse();
|
||||
|
||||
$this->assertResponse($response, 'admin/shipment/get_shipment_adjustments', Response::HTTP_OK);
|
||||
}
|
||||
|
||||
/** @return array<string, string> */
|
||||
private function buildHeadersWithMergePatchJson(string $adminEmail): array
|
||||
{
|
||||
|
|
|
|||
|
|
@ -58,6 +58,6 @@ final class OrderItemsTest extends JsonApiTestCase
|
|||
|
||||
$response = $this->client->getResponse();
|
||||
|
||||
$this->assertResponse($response, 'admin/order_item/get_order_item_adjustments_response', Response::HTTP_OK);
|
||||
$this->assertResponse($response, 'admin/order_item/get_order_item_adjustments', Response::HTTP_OK);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,12 +41,13 @@ final class OrdersTest extends JsonApiTestCase
|
|||
'country.yaml',
|
||||
'shipping_method.yaml',
|
||||
'payment_method.yaml',
|
||||
'cart/promotion.yaml',
|
||||
]);
|
||||
|
||||
$this->placeOrder(self::TEST_TOKEN_VALUE);
|
||||
|
||||
$this->requestGet(uri: sprintf('/api/v2/admin/orders/%s/adjustments', self::TEST_TOKEN_VALUE));
|
||||
|
||||
$this->assertResponseSuccessful('admin/order/get_adjustments_for_a_given_order_response');
|
||||
$this->assertResponseSuccessful('admin/order/get_adjustments_for_a_given_order');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ final class ShipmentsTest extends JsonApiTestCase
|
|||
'country.yaml',
|
||||
'shipping_method.yaml',
|
||||
'payment_method.yaml',
|
||||
'cart/promotion.yaml',
|
||||
]);
|
||||
|
||||
$order = $this->placeOrder('token');
|
||||
|
|
|
|||
|
|
@ -63,3 +63,11 @@ Sylius\Component\Core\Model\Adjustment:
|
|||
adjustable: '@order_item_unit'
|
||||
createdAt: "<(new \\DateTime())>"
|
||||
updatedAt: "<(new \\DateTime())>"
|
||||
adjustment_3:
|
||||
type: shipping
|
||||
label: UPS
|
||||
amount: 500
|
||||
neutral: false
|
||||
adjustable: '@order'
|
||||
createdAt: "<(new \\DateTime())>"
|
||||
updatedAt: "<(new \\DateTime())>"
|
||||
|
|
|
|||
|
|
@ -0,0 +1,64 @@
|
|||
{
|
||||
"@context": "/api/v2/contexts/Adjustment",
|
||||
"@id": "/api/v2/admin/orders/nAWw2jewpA/adjustments",
|
||||
"@type": "hydra:Collection",
|
||||
"hydra:totalItems": 4,
|
||||
"hydra:member": [
|
||||
{
|
||||
"@id": "/api/v2/admin/adjustments/@integer@",
|
||||
"@type": "Adjustment",
|
||||
"shipment": "/api/v2/admin/shipments/@integer@",
|
||||
"id": @integer@,
|
||||
"order": "/api/v2/admin/orders/nAWw2jewpA",
|
||||
"orderItem": null,
|
||||
"orderItemUnit": null,
|
||||
"type": "shipping",
|
||||
"label": "UPS",
|
||||
"amount": 500,
|
||||
"neutral": false,
|
||||
"locked": false
|
||||
},
|
||||
{
|
||||
"@id": "/api/v2/admin/adjustments/@integer@",
|
||||
"@type": "Adjustment",
|
||||
"shipment": null,
|
||||
"id": @integer@,
|
||||
"order": null,
|
||||
"orderItem": null,
|
||||
"orderItemUnit": "/api/v2/admin/order-item-units/@integer@",
|
||||
"type": "order_promotion",
|
||||
"label": "50% Off on your first order",
|
||||
"amount": -1000,
|
||||
"neutral": false,
|
||||
"locked": false
|
||||
},
|
||||
{
|
||||
"@id": "/api/v2/admin/adjustments/@integer@",
|
||||
"@type": "Adjustment",
|
||||
"shipment": null,
|
||||
"id": @integer@,
|
||||
"order": null,
|
||||
"orderItem": null,
|
||||
"orderItemUnit": "/api/v2/admin/order-item-units/@integer@",
|
||||
"type": "order_promotion",
|
||||
"label": "50% Off on your first order",
|
||||
"amount": -1000,
|
||||
"neutral": false,
|
||||
"locked": false
|
||||
},
|
||||
{
|
||||
"@id": "/api/v2/admin/adjustments/@integer@",
|
||||
"@type": "Adjustment",
|
||||
"shipment": null,
|
||||
"id": @integer@,
|
||||
"order": null,
|
||||
"orderItem": null,
|
||||
"orderItemUnit": "/api/v2/admin/order-item-units/@integer@",
|
||||
"type": "order_promotion",
|
||||
"label": "50% Off on your first order",
|
||||
"amount": -1000,
|
||||
"neutral": false,
|
||||
"locked": false
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
{
|
||||
"@context": "/api/v2/contexts/Adjustment",
|
||||
"@id": "/api/v2/admin/orders/nAWw2jewpA/adjustments",
|
||||
"@type": "hydra:Collection",
|
||||
"hydra:totalItems": 1,
|
||||
"hydra:member": [
|
||||
{
|
||||
"@id": "/api/v2/admin/adjustments/@integer@",
|
||||
"@type": "Adjustment",
|
||||
"id": @integer@,
|
||||
"type": "shipping",
|
||||
"label": "UPS",
|
||||
"order": "/api/v2/admin/orders/nAWw2jewpA",
|
||||
"orderItem": null,
|
||||
"orderItemUnit": null,
|
||||
"shipment": "/api/v2/admin/shipments/@integer@",
|
||||
"amount": 500,
|
||||
"neutral": false,
|
||||
"locked": false
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -1,17 +1,44 @@
|
|||
{
|
||||
"@context": "\/api\/v2\/contexts\/Adjustment",
|
||||
"@id": "/api/v2/shop/orders/nAWw2jewpA/adjustments",
|
||||
"@type": "hydra:Collection",
|
||||
"hydra:member": [
|
||||
{
|
||||
"@id": "\/api\/v2\/shop\/adjustments\/@integer@",
|
||||
"@type": "Adjustment",
|
||||
"id": @integer@,
|
||||
"type": "shipping",
|
||||
"label": "UPS",
|
||||
"amount": 500,
|
||||
"neutral": false
|
||||
}
|
||||
],
|
||||
"hydra:totalItems": 1
|
||||
"@context": "/api/v2/contexts/Adjustment",
|
||||
"@id": "/api/v2/shop/orders/TOKEN/adjustments",
|
||||
"@type": "hydra:Collection",
|
||||
"hydra:totalItems": 4,
|
||||
"hydra:member": [
|
||||
{
|
||||
"@id": "/api/v2/shop/adjustments/@integer@",
|
||||
"@type": "Adjustment",
|
||||
"id": @integer@,
|
||||
"type": "shipping",
|
||||
"label": "UPS",
|
||||
"amount": 500,
|
||||
"neutral": false
|
||||
},
|
||||
{
|
||||
"@id": "/api/v2/shop/adjustments/@integer@",
|
||||
"@type": "Adjustment",
|
||||
"id": @integer@,
|
||||
"type": "order_promotion",
|
||||
"label": "50% Off on your first order",
|
||||
"amount": -1000,
|
||||
"neutral": false
|
||||
},
|
||||
{
|
||||
"@id": "/api/v2/shop/adjustments/@integer@",
|
||||
"@type": "Adjustment",
|
||||
"id": @integer@,
|
||||
"type": "order_promotion",
|
||||
"label": "50% Off on your first order",
|
||||
"amount": -1000,
|
||||
"neutral": false
|
||||
},
|
||||
{
|
||||
"@id": "/api/v2/shop/adjustments/@integer@",
|
||||
"@type": "Adjustment",
|
||||
"id": @integer@,
|
||||
"type": "order_promotion",
|
||||
"label": "50% Off on your first order",
|
||||
"amount": -1000,
|
||||
"neutral": false
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
57
tests/Api/Shop/OrdersTest.php
Normal file
57
tests/Api/Shop/OrdersTest.php
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Sylius Sp. z o.o.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Tests\Api\Shop;
|
||||
|
||||
use Sylius\Component\Customer\Model\CustomerInterface;
|
||||
use Sylius\Tests\Api\JsonApiTestCase;
|
||||
use Sylius\Tests\Api\Utils\OrderPlacerTrait;
|
||||
use Sylius\Tests\Api\Utils\ShopUserLoginTrait;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
final class OrdersTest extends JsonApiTestCase
|
||||
{
|
||||
use OrderPlacerTrait;
|
||||
use ShopUserLoginTrait;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->setUpOrderPlacer();
|
||||
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_gets_order_adjustments(): void
|
||||
{
|
||||
$this->loadFixturesFromFiles([
|
||||
'channel.yaml',
|
||||
'cart.yaml',
|
||||
'country.yaml',
|
||||
'shipping_method.yaml',
|
||||
'payment_method.yaml',
|
||||
'cart/promotion.yaml',
|
||||
]);
|
||||
|
||||
$this->placeOrder('TOKEN');
|
||||
|
||||
$this->client->request(
|
||||
method: 'GET',
|
||||
uri: '/api/v2/shop/orders/TOKEN/adjustments',
|
||||
server: self::CONTENT_TYPE_HEADER,
|
||||
);
|
||||
$response = $this->client->getResponse();
|
||||
|
||||
$this->assertResponse($response, 'shop/order/get_order_adjustments', Response::HTTP_OK);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue