diff --git a/disabledTests/Api/Admin/OrderItemUnitsTest.php b/disabledTests/Api/Admin/OrderItemUnitsTest.php index 3c2126aa01..82a01cbb32 100644 --- a/disabledTests/Api/Admin/OrderItemUnitsTest.php +++ b/disabledTests/Api/Admin/OrderItemUnitsTest.php @@ -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); - } } diff --git a/disabledTests/Api/Admin/OrderItemsTest.php b/disabledTests/Api/Admin/OrderItemsTest.php index 22bfaa3186..84f96bfb08 100644 --- a/disabledTests/Api/Admin/OrderItemsTest.php +++ b/disabledTests/Api/Admin/OrderItemsTest.php @@ -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); - } } diff --git a/disabledTests/Api/Admin/OrdersTest.php b/disabledTests/Api/Admin/OrdersTest.php index 0da0974457..2a7e443a7a 100644 --- a/disabledTests/Api/Admin/OrdersTest.php +++ b/disabledTests/Api/Admin/OrdersTest.php @@ -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 { diff --git a/disabledTests/Api/Admin/ShipmentsTest.php b/disabledTests/Api/Admin/ShipmentsTest.php index a96eaf99a1..aba0606c31 100644 --- a/disabledTests/Api/Admin/ShipmentsTest.php +++ b/disabledTests/Api/Admin/ShipmentsTest.php @@ -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 */ private function buildHeadersWithMergePatchJson(string $adminEmail): array { diff --git a/tests/Api/Admin/OrderItemsTest.php b/tests/Api/Admin/OrderItemsTest.php index e45d3766c6..f6c1bd9f7e 100644 --- a/tests/Api/Admin/OrderItemsTest.php +++ b/tests/Api/Admin/OrderItemsTest.php @@ -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); } } diff --git a/tests/Api/Admin/OrdersTest.php b/tests/Api/Admin/OrdersTest.php index 48b83f21e3..36f0763fec 100644 --- a/tests/Api/Admin/OrdersTest.php +++ b/tests/Api/Admin/OrdersTest.php @@ -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'); } } diff --git a/tests/Api/Admin/ShipmentsTest.php b/tests/Api/Admin/ShipmentsTest.php index 8e588d4000..fe5a481832 100644 --- a/tests/Api/Admin/ShipmentsTest.php +++ b/tests/Api/Admin/ShipmentsTest.php @@ -38,6 +38,7 @@ final class ShipmentsTest extends JsonApiTestCase 'country.yaml', 'shipping_method.yaml', 'payment_method.yaml', + 'cart/promotion.yaml', ]); $order = $this->placeOrder('token'); diff --git a/tests/Api/DataFixtures/ORM/order/order_with_item.yaml b/tests/Api/DataFixtures/ORM/order/order_with_item.yaml index ec7971c8ec..8e84f78143 100644 --- a/tests/Api/DataFixtures/ORM/order/order_with_item.yaml +++ b/tests/Api/DataFixtures/ORM/order/order_with_item.yaml @@ -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())>" diff --git a/tests/Api/Responses/admin/order/get_adjustments_for_a_given_order.json b/tests/Api/Responses/admin/order/get_adjustments_for_a_given_order.json new file mode 100644 index 0000000000..2b2f4d453c --- /dev/null +++ b/tests/Api/Responses/admin/order/get_adjustments_for_a_given_order.json @@ -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 + } + ] +} diff --git a/tests/Api/Responses/admin/order/get_adjustments_for_a_given_order_response.json b/tests/Api/Responses/admin/order/get_adjustments_for_a_given_order_response.json deleted file mode 100644 index 1b5885e067..0000000000 --- a/tests/Api/Responses/admin/order/get_adjustments_for_a_given_order_response.json +++ /dev/null @@ -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 - } - ] -} diff --git a/tests/Api/Responses/admin/order_item/get_order_item_adjustments_response.json b/tests/Api/Responses/admin/order_item/get_order_item_adjustments.json similarity index 100% rename from tests/Api/Responses/admin/order_item/get_order_item_adjustments_response.json rename to tests/Api/Responses/admin/order_item/get_order_item_adjustments.json diff --git a/tests/Api/Responses/shop/order/get_order_adjustments.json b/tests/Api/Responses/shop/order/get_order_adjustments.json index c7b9bb6db7..9ecd766c77 100644 --- a/tests/Api/Responses/shop/order/get_order_adjustments.json +++ b/tests/Api/Responses/shop/order/get_order_adjustments.json @@ -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 + } + ] } diff --git a/tests/Api/Shop/OrdersTest.php b/tests/Api/Shop/OrdersTest.php new file mode 100644 index 0000000000..2a9fc9fad5 --- /dev/null +++ b/tests/Api/Shop/OrdersTest.php @@ -0,0 +1,57 @@ +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); + } +}