From 58c8b1fe798ba6c15a185ff5aa3bd71c6eab3b9a Mon Sep 17 00:00:00 2001 From: Grzegorz Sadowski Date: Wed, 17 Jul 2019 09:13:05 +0200 Subject: [PATCH] [Order] Remove channel code from order routes --- UPGRADE.md | 3 +- src/Resources/config/routing.yml | 2 +- tests/Controller/Order/OrderShowApiTest.php | 32 +++++--------------- tests/Controller/Order/OrdersListApiTest.php | 20 +++--------- 4 files changed, 16 insertions(+), 41 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index 1e5ae615e..bf09ef36a 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -23,11 +23,12 @@ | `taxon-products-by-slug/{taxonSlug}` | `taxon-products/by-slug/{taxonSlug}` | | `product/by-slug/{slug}/reviews` | `products/by-slug/{slug}/reviews` | -* The channel code has been removed from checkout routes: +* The channel code has been removed from routes: | Old Route | New route | |:--------------------------------------|:---------------------------------------| | `{channelCode}/checkout/*` | `checkout/*` | + | `{channelCode}/orders/*` | `orders/*` | # UPGRADE FROM 1.0.0-beta.17 to 1.0.0-beta.18 diff --git a/src/Resources/config/routing.yml b/src/Resources/config/routing.yml index 7aa51d702..4ac6a53ed 100644 --- a/src/Resources/config/routing.yml +++ b/src/Resources/config/routing.yml @@ -36,4 +36,4 @@ sylius_shop_api_address_book: sylius_shop_api_order: resource: "@ShopApiPlugin/Resources/config/routing/order.yml" - prefix: /shop-api/{channelCode} + prefix: /shop-api diff --git a/tests/Controller/Order/OrderShowApiTest.php b/tests/Controller/Order/OrderShowApiTest.php index 1c955bd55..b83432101 100644 --- a/tests/Controller/Order/OrderShowApiTest.php +++ b/tests/Controller/Order/OrderShowApiTest.php @@ -27,9 +27,7 @@ public function it_shows_details_of_placed_order_of_logged_in_customer(): void $this->placeOrderForCustomerWithEmail($email, $token); - $this->client->request('GET', '/shop-api/WEB_GB/orders/' . $token, [], [], self::CONTENT_TYPE_HEADER); - $response = $this->client->getResponse(); - + $response = $this->showOrder($token); $this->assertResponse($response, 'order/order_details_response', Response::HTTP_OK); } @@ -44,9 +42,7 @@ public function it_shows_details_of_placed_order_of_guest_customer(): void $this->placeOrderForCustomerWithEmail($email, $token); - $this->client->request('GET', '/shop-api/WEB_GB/orders/' . $token, [], [], self::CONTENT_TYPE_HEADER); - $response = $this->client->getResponse(); - + $response = $this->showOrder($token); $this->assertResponse($response, 'order/order_details_response_guest', Response::HTTP_OK); } @@ -58,9 +54,7 @@ public function it_returns_a_not_found_exception_if_there_is_no_placed_order_wit $this->loadFixturesFromFiles(['channel.yml', 'customer.yml']); $this->logInUser('oliver@queen.com', '123password'); - $this->client->request('GET', '/shop-api/WEB_GB/orders/NOT_EXISTING_TOKEN', [], [], self::CONTENT_TYPE_HEADER); - $response = $this->client->getResponse(); - + $response = $this->showOrder('NOT_EXISTING_TOKEN'); $this->assertResponse($response, 'order/order_not_found_response', Response::HTTP_NOT_FOUND); } @@ -71,9 +65,7 @@ public function it_returns_a_not_found_exception_if_there_is_no_placed_order_wit { $this->loadFixturesFromFiles(['channel.yml']); - $this->client->request('GET', '/shop-api/WEB_GB/orders/NOT_EXISTING_TOKEN', [], [], self::CONTENT_TYPE_HEADER); - $response = $this->client->getResponse(); - + $response = $this->showOrder('NOT_EXISTING_TOKEN'); $this->assertResponse($response, 'order/order_not_found_response_guest', Response::HTTP_NOT_FOUND); } @@ -93,22 +85,14 @@ public function it_returns_a_not_found_exception_if_placed_order_with_given_toke //logout $this->client->setServerParameter('HTTP_Authorization', null); - $this->client->request('GET', '/shop-api/WEB_GB/orders/' . $token, [], [], self::CONTENT_TYPE_HEADER); - $response = $this->client->getResponse(); - + $response = $this->showOrder($token); $this->assertResponse($response, 'order/order_placed_by_registered_customer', Response::HTTP_NOT_FOUND); } - /** - * @test - */ - public function it_does_not_show_order_details_in_non_existent_channel(): void + private function showOrder(string $token): Response { - $this->loadFixturesFromFiles(['channel.yml']); - - $this->client->request('GET', '/shop-api/SPACE_KLINGON/orders/ORDER_TOKEN', [], [], self::CONTENT_TYPE_HEADER); - $response = $this->client->getResponse(); + $this->client->request('GET', sprintf('/shop-api/orders/%s', $token), [], [], self::CONTENT_TYPE_HEADER); - $this->assertResponse($response, 'channel_has_not_been_found_response', Response::HTTP_NOT_FOUND); + return $this->client->getResponse(); } } diff --git a/tests/Controller/Order/OrdersListApiTest.php b/tests/Controller/Order/OrdersListApiTest.php index c24346f43..e9bf53581 100644 --- a/tests/Controller/Order/OrdersListApiTest.php +++ b/tests/Controller/Order/OrdersListApiTest.php @@ -27,9 +27,7 @@ public function it_lists_only_placed_orders_of_logged_in_customer(): void $this->placeOrderForCustomerWithEmail($email, $token); - $this->client->request('GET', '/shop-api/WEB_GB/orders', [], [], self::CONTENT_TYPE_HEADER); - $response = $this->client->getResponse(); - + $response = $this->listOrders(); $this->assertResponse($response, 'order/orders_list_response', Response::HTTP_OK); } @@ -40,22 +38,14 @@ public function it_returns_an_unauthorized_exception_if_there_is_no_logged_in_us { $this->loadFixturesFromFile('channel.yml'); - $this->client->request('GET', '/shop-api/WEB_GB/orders', [], [], self::CONTENT_TYPE_HEADER); - $response = $this->client->getResponse(); - + $response = $this->listOrders(); $this->assertResponseCode($response, Response::HTTP_UNAUTHORIZED); } - /** - * @test - */ - public function it_does_not_show_orders_list_in_non_existent_channel(): void + private function listOrders(): Response { - $this->loadFixturesFromFile('channel.yml'); - - $this->client->request('GET', '/shop-api/SPACE_KLINGON/orders', [], [], self::CONTENT_TYPE_HEADER); - $response = $this->client->getResponse(); + $this->client->request('GET', '/shop-api/orders', [], [], self::CONTENT_TYPE_HEADER); - $this->assertResponse($response, 'channel_has_not_been_found_response', Response::HTTP_NOT_FOUND); + return $this->client->getResponse(); } }