Skip to content

Commit

Permalink
Removing the old routes and fixing the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mamazu committed Apr 6, 2019
1 parent 5f557a5 commit 3d06a4d
Show file tree
Hide file tree
Showing 22 changed files with 143 additions and 137 deletions.
8 changes: 4 additions & 4 deletions doc/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ paths:
security:
- {}
- bearerAuth: []
/{channelCode}/taxon-products/by-slug/{slug}:
/{channelCode}/taxon-products/by-slug/{taxonSlug}:
parameters:
- $ref: "#/parameters/ChannelCode"
get:
Expand All @@ -462,7 +462,7 @@ paths:
description: "This endpoint will return a paginated list of products for given taxon."
operationId: "productCatalogBySlug"
parameters:
- name: "slug"
- name: "taxonSlug"
in: "path"
description: "Slug of taxonomy for which products should be listed."
required: true
Expand All @@ -487,7 +487,7 @@ paths:
description: "Paginated product list."
schema:
$ref: "#/definitions/ProductsPage"
/{channelCode}/taxon-products-by-slug/{slug}:
/{channelCode}/taxon-products-by-slug/{taxonSlug}:
parameters:
- $ref: "#/parameters/ChannelCode"
get:
Expand All @@ -498,7 +498,7 @@ paths:
description: "This endpoint will return a paginated list of products for given taxon."
operationId: "productCatalogBySlug_deprecated"
parameters:
- name: "slug"
- name: "taxonSlug"
in: "path"
description: "Slug of taxonomy for which products should be listed."
required: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function __invoke(Request $request): Response
{
try {
return $this->viewHandler->handle(View::create($this->productCatalogQuery->findByTaxonSlug(
$request->attributes->get('slug'),
$request->attributes->get('taxonSlug'),
$request->attributes->get('channelCode'),
new PaginatorDetails($request->attributes->get('_route'), $request->query->all()),
$request->query->get('locale')
Expand Down
46 changes: 23 additions & 23 deletions src/Resources/config/routing/productByCode.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
sylius_shop_api_product_show_details_by_code_deprecated:
path: /products/{code}
methods: [GET]
defaults:
_controller: sylius.shop_api_plugin.controller.product.show_product_details_by_code_action

sylius_shop_api_product_show_catalog_by_code_deprecated:
path: /taxon-products/{code}
methods: [GET]
defaults:
_controller: sylius.shop_api_plugin.controller.product.show_product_catalog_by_taxon_code_action

sylius_shop_api_product_show_reviews_by_code_depricated:
path: /products/{code}/reviews
methods: [GET]
defaults:
_controller: sylius.shop_api_plugin.controller.product.show_product_reviews_by_code_action

sylius_shop_api_add_product_review_by_code_deprecated:
path: /products/{code}/reviews
methods: [POST]
defaults:
_controller: sylius.shop_api_plugin.controller.product.add_review_by_code_action
#sylius_shop_api_product_show_details_by_code_deprecated:
# path: /products/{code}
# methods: [GET]
# defaults:
# _controller: sylius.shop_api_plugin.controller.product.show_product_details_by_code_action
#
#sylius_shop_api_product_show_catalog_by_code_deprecated:
# path: /taxon-products/{code}
# methods: [GET]
# defaults:
# _controller: sylius.shop_api_plugin.controller.product.show_product_catalog_by_taxon_code_action
#
#sylius_shop_api_product_show_reviews_by_code_depricated:
# path: /products/{code}/reviews
# methods: [GET]
# defaults:
# _controller: sylius.shop_api_plugin.controller.product.show_product_reviews_by_code_action
#
#sylius_shop_api_add_product_review_by_code_deprecated:
# path: /products/{code}/reviews
# methods: [POST]
# defaults:
# _controller: sylius.shop_api_plugin.controller.product.add_review_by_code_action

# New routes
sylius_shop_api_product_show_details_by_code:
Expand Down
58 changes: 32 additions & 26 deletions src/Resources/config/routing/productBySlug.yml
Original file line number Diff line number Diff line change
@@ -1,50 +1,56 @@
sylius_shop_api_product_show_details_by_slug_deprecated:
path: /products-by-slug/{slug}
methods: [GET]
defaults:
_controller: 'Symfony\Bundle\FrameworkBundle\Controller\RedirectController:urlRedirectAction'
path: /shop-api/{channelCode}/products/by-slug/{slug}
permanent: true

sylius_shop_api_add_product_review_by_slug_deprecated:
path: /product-reviews-by-slug/{slug}
methods: [POST]
defaults:
_controller: sylius.shop_api_plugin.controller.product.add_review_by_slug_action

sylius_shop_api_product_show_catalog_by_slug_deprecated:
path: /taxon-products-by-slug/{taxonSlug}
methods: [GET]
defaults:
_controller: sylius.shop_api_plugin.controller.product.show_product_catalog_by_taxon_slug_action

sylius_shop_api_product_show_reviews_by_slug_deprecated:
path: /product-reviews-by-slug/{slug}
methods: [GET]
defaults:
_controller: sylius.shop_api_plugin.controller.product.show_product_reviews_by_slug_action
#sylius_shop_api_product_show_details_by_slug_deprecated:
# path: /products-by-slug/{slug}
# methods: [GET]
# defaults:
# _controller: sylius.shop_api_plugin.controller.product.show_product_details_by_slug_action
#
#sylius_shop_api_add_product_review_by_slug_deprecated:
# path: /product-reviews-by-slug/{slug}
# methods: [POST]
# defaults:
# _controller: sylius.shop_api_plugin.controller.product.add_review_by_slug_action
#
#sylius_shop_api_product_show_catalog_by_slug_deprecated:
# path: /taxon-products-by-slug/{taxonSlug}
# methods: [GET]
# defaults:
# _controller: sylius.shop_api_plugin.controller.product.show_product_catalog_by_taxon_slug_action
#
#sylius_shop_api_product_show_reviews_by_slug_deprecated:
# path: /product-reviews-by-slug/{slug}
# methods: [GET]
# defaults:
# _controller: sylius.shop_api_plugin.controller.product.show_product_reviews_by_slug_action

# New routes
sylius_shop_api_product_show_details_by_slug:
path: /products/by-slug/{slug}
methods: [GET]
defaults:
_controller: sylius.shop_api_plugin.controller.product.show_product_details_by_slug_action
requirements:
slug: .+

sylius_shop_api_product_show_catalog_by_slug:
path: /taxon-products/by-slug/{slug}
path: /taxon-products/by-slug/{taxonSlug}
methods: [GET]
defaults:
_controller: sylius.shop_api_plugin.controller.product.show_product_catalog_by_taxon_slug_action
requirements:
taxonSlug: .+

sylius_shop_api_product_show_reviews_by_slug:
path: /product/by-slug/{slug}/reviews
methods: [GET]
defaults:
_controller: sylius.shop_api_plugin.controller.product.show_product_reviews_by_slug_action
requirements:
slug: .+

sylius_shop_api_add_product_review_by_slug:
path: /product/by-slug/{slug}/reviews
methods: [POST]
defaults:
_controller: sylius.shop_api_plugin.controller.product.add_review_by_slug_action
requirements:
slug: .+
10 changes: 5 additions & 5 deletions tests/Controller/Product/ProductAddReviewByCodeApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function it_adds_review_to_product(): void
"email": "oliver@example.com"
}
EOT;
$this->client->request('POST', '/shop-api/WEB_GB/products/LOGAN_MUG_CODE/reviews', [], [], self::CONTENT_TYPE_HEADER, $data);
$this->client->request('POST', '/shop-api/WEB_GB/products/by-code/LOGAN_MUG_CODE/reviews', [], [], self::CONTENT_TYPE_HEADER, $data);
$response = $this->client->getResponse();

$this->assertResponseCode($response, Response::HTTP_CREATED);
Expand All @@ -47,7 +47,7 @@ public function it_adds_review_to_the_product_for_registered_user(): void
"email": "oliver@example.com"
}
EOT;
$this->client->request('POST', '/shop-api/WEB_GB/products/LOGAN_MUG_CODE/reviews', [], [], self::CONTENT_TYPE_HEADER, $data);
$this->client->request('POST', '/shop-api/WEB_GB/products/by-code/LOGAN_MUG_CODE/reviews', [], [], self::CONTENT_TYPE_HEADER, $data);
$response = $this->client->getResponse();

$this->assertResponseCode($response, Response::HTTP_CREATED);
Expand All @@ -69,7 +69,7 @@ public function it_does_not_allow_to_add_product_review_by_code_in_non_existent_
"email": "oliver@example.com"
}
EOT;
$this->client->request('POST', '/shop-api/SPACE_KLINGON/products/LOGAN_MUG_CODE/reviews', [], [], self::CONTENT_TYPE_HEADER, $data);
$this->client->request('POST', '/shop-api/SPACE_KLINGON/products/by-code/LOGAN_MUG_CODE/reviews', [], [], self::CONTENT_TYPE_HEADER, $data);
$response = $this->client->getResponse();

$this->assertResponse($response, 'channel_has_not_been_found_response', Response::HTTP_NOT_FOUND);
Expand All @@ -93,7 +93,7 @@ public function it_does_not_allow_to_add_review_when_rating_is_out_of_bounds():
}
EOT;

$this->client->request('POST', '/shop-api/WEB_GB/products/LOGAN_MUG_CODE/reviews', [], [], self::CONTENT_TYPE_HEADER, $data);
$this->client->request('POST', '/shop-api/WEB_GB/products/by-code/LOGAN_MUG_CODE/reviews', [], [], self::CONTENT_TYPE_HEADER, $data);

$response = $this->client->getResponse();
$this->assertResponse($response, 'reviews/add_review_failed_rating', Response::HTTP_BAD_REQUEST);
Expand All @@ -117,7 +117,7 @@ public function it_does_not_allow_to_add_review_when_email_is_not_valid(): void
}
EOT;

$this->client->request('POST', '/shop-api/WEB_GB/products/LOGAN_MUG_CODE/reviews', [], [], self::CONTENT_TYPE_HEADER, $data);
$this->client->request('POST', '/shop-api/WEB_GB/products/by-code/LOGAN_MUG_CODE/reviews', [], [], self::CONTENT_TYPE_HEADER, $data);

$response = $this->client->getResponse();
$this->assertResponse($response, 'reviews/add_review_failed_email', Response::HTTP_BAD_REQUEST);
Expand Down
10 changes: 5 additions & 5 deletions tests/Controller/Product/ProductAddReviewBySlugApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function it_adds_review_to_product(): void
"email": "oliver@example.com"
}
EOT;
$this->client->request('POST', '/shop-api/WEB_GB/product-reviews-by-slug/logan-mug', [], [], self::CONTENT_TYPE_HEADER, $data);
$this->client->request('POST', '/shop-api/WEB_GB/product/by-slug/logan-mug/reviews', [], [], self::CONTENT_TYPE_HEADER, $data);
$response = $this->client->getResponse();

$this->assertResponseCode($response, Response::HTTP_CREATED);
Expand All @@ -47,7 +47,7 @@ public function it_adds_review_to_the_product_for_registered_user(): void
"email": "oliver@example.com"
}
EOT;
$this->client->request('POST', '/shop-api/WEB_GB/product-reviews-by-slug/logan-mug', [], [], self::CONTENT_TYPE_HEADER, $data);
$this->client->request('POST', '/shop-api/WEB_GB/product/by-slug/logan-mug/reviews', [], [], self::CONTENT_TYPE_HEADER, $data);
$response = $this->client->getResponse();

$this->assertResponseCode($response, Response::HTTP_CREATED);
Expand All @@ -69,7 +69,7 @@ public function it_does_not_allow_to_add_product_review_by_slug_in_non_existent_
"email": "oliver@example.com"
}
EOT;
$this->client->request('POST', '/shop-api/SPACE_KLINGON/product-reviews-by-slug/logan-mug', [], [], self::CONTENT_TYPE_HEADER, $data);
$this->client->request('POST', '/shop-api/SPACE_KLINGON/product/by-slug/logan-mug/reviews', [], [], self::CONTENT_TYPE_HEADER, $data);
$response = $this->client->getResponse();

$this->assertResponse($response, 'channel_has_not_been_found_response', Response::HTTP_NOT_FOUND);
Expand All @@ -92,7 +92,7 @@ public function it_does_not_allow_to_add_review_when_rating_is_out_of_bounds():
}
EOT;

$this->client->request('POST', '/shop-api/WEB_GB/product-reviews-by-slug/mug', [], [], self::CONTENT_TYPE_HEADER, $data);
$this->client->request('POST', '/shop-api/WEB_GB/product/by-slug/mug/reviews', [], [], self::CONTENT_TYPE_HEADER, $data);

$response = $this->client->getResponse();
$this->assertResponse($response, 'reviews/add_review_failed_rating', Response::HTTP_BAD_REQUEST);
Expand All @@ -115,7 +115,7 @@ public function it_does_not_allow_to_add_review_when_rating_email_is_not_valid()
}
EOT;

$this->client->request('POST', '/shop-api/WEB_GB/product-reviews-by-slug/mug', [], [], self::CONTENT_TYPE_HEADER, $data);
$this->client->request('POST', '/shop-api/WEB_GB/product/by-slug/mug/reviews', [], [], self::CONTENT_TYPE_HEADER, $data);

$response = $this->client->getResponse();
$this->assertResponse($response, 'reviews/add_review_failed_email', Response::HTTP_BAD_REQUEST);
Expand Down
10 changes: 5 additions & 5 deletions tests/Controller/Product/ProductShowCatalogByCodeApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function it_shows_paginated_products_from_some_taxon_by_code(): void
{
$this->loadFixturesFromFiles(['shop.yml']);

$this->client->request('GET', '/shop-api/WEB_GB/taxon-products/BRAND', [], [], self::CONTENT_TYPE_HEADER);
$this->client->request('GET', '/shop-api/WEB_GB/taxon-products/by-code/BRAND', [], [], self::CONTENT_TYPE_HEADER);
$response = $this->client->getResponse();

$this->assertResponse($response, 'product/product_list_page_by_code_response', Response::HTTP_OK);
Expand All @@ -29,7 +29,7 @@ public function it_shows_products_for_sub_taxons_by_code(): void
{
$this->loadFixturesFromFiles(['shop.yml']);

$this->client->request('GET', '/shop-api/WEB_GB/taxon-products/WOMEN_T_SHIRTS', [], [], self::CONTENT_TYPE_HEADER);
$this->client->request('GET', '/shop-api/WEB_GB/taxon-products/by-code/WOMEN_T_SHIRTS', [], [], self::CONTENT_TYPE_HEADER);
$response = $this->client->getResponse();

$this->assertResponse($response, 'product/product_t_shirt_list_page_by_code_response', Response::HTTP_OK);
Expand All @@ -42,7 +42,7 @@ public function it_shows_paginated_products_from_some_taxon_by_code_in_different
{
$this->loadFixturesFromFiles(['shop.yml']);

$this->client->request('GET', '/shop-api/WEB_GB/taxon-products/BRAND?locale=de_DE', [], [], self::CONTENT_TYPE_HEADER);
$this->client->request('GET', '/shop-api/WEB_GB/taxon-products/by-code/BRAND?locale=de_DE', [], [], self::CONTENT_TYPE_HEADER);
$response = $this->client->getResponse();

$this->assertResponse($response, 'product/german_product_list_page_by_code_response', Response::HTTP_OK);
Expand All @@ -55,7 +55,7 @@ public function it_shows_second_page_of_paginated_products_from_some_taxon_by_co
{
$this->loadFixturesFromFiles(['shop.yml']);

$this->client->request('GET', '/shop-api/WEB_GB/taxon-products/BRAND?limit=1&page=2', [], [], self::CONTENT_TYPE_HEADER);
$this->client->request('GET', '/shop-api/WEB_GB/taxon-products/by-code/BRAND?limit=1&page=2', [], [], self::CONTENT_TYPE_HEADER);
$response = $this->client->getResponse();

$this->assertResponse($response, 'product/limited_product_list_page_by_code_response', Response::HTTP_OK);
Expand All @@ -68,7 +68,7 @@ public function it_does_not_show_product_catalog_by_code_in_non_existent_channel
{
$this->loadFixturesFromFiles(['shop.yml']);

$this->client->request('GET', '/shop-api/SPACE_KLINGON/taxon-products/BRAND', [], [], self::CONTENT_TYPE_HEADER);
$this->client->request('GET', '/shop-api/SPACE_KLINGON/taxon-products/by-code/BRAND', [], [], self::CONTENT_TYPE_HEADER);
$response = $this->client->getResponse();

$this->assertResponse($response, 'channel_has_not_been_found_response', Response::HTTP_NOT_FOUND);
Expand Down
14 changes: 7 additions & 7 deletions tests/Controller/Product/ProductShowCatalogBySlugApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function it_shows_paginated_products_from_some_taxon_by_slug(): void
{
$this->loadFixturesFromFiles(['shop.yml']);

$this->client->request('GET', '/shop-api/WEB_GB/taxon-products-by-slug/brands', [], [], self::CONTENT_TYPE_HEADER);
$this->client->request('GET', '/shop-api/WEB_GB/taxon-products/by-slug/brands', [], [], self::CONTENT_TYPE_HEADER);
$response = $this->client->getResponse();

$this->assertResponse($response, 'product/product_list_page_by_slug_response', Response::HTTP_OK);
Expand All @@ -29,7 +29,7 @@ public function it_shows_products_for_sub_taxons_by_slug(): void
{
$this->loadFixturesFromFiles(['shop.yml']);

$this->client->request('GET', '/shop-api/WEB_GB/taxon-products-by-slug/categories/t-shirts/women-t-shirts', [], [], self::CONTENT_TYPE_HEADER);
$this->client->request('GET', '/shop-api/WEB_GB/taxon-products/by-slug/categories/t-shirts/women-t-shirts', [], [], self::CONTENT_TYPE_HEADER);
$response = $this->client->getResponse();

$this->assertResponse($response, 'product/product_t_shirt_list_page_by_slug_response', Response::HTTP_OK);
Expand All @@ -42,7 +42,7 @@ public function it_shows_paginated_products_from_some_taxon_by_slug_in_different
{
$this->loadFixturesFromFiles(['shop.yml']);

$this->client->request('GET', '/shop-api/WEB_GB/taxon-products-by-slug/marken?locale=de_DE', [], [], self::CONTENT_TYPE_HEADER);
$this->client->request('GET', '/shop-api/WEB_GB/taxon-products/by-slug/marken?locale=de_DE', [], [], self::CONTENT_TYPE_HEADER);
$response = $this->client->getResponse();

$this->assertResponse($response, 'product/german_product_list_page_by_slug_response', Response::HTTP_OK);
Expand All @@ -55,7 +55,7 @@ public function it_shows_second_page_of_paginated_products_from_some_taxon_by_sl
{
$this->loadFixturesFromFiles(['shop.yml']);

$this->client->request('GET', '/shop-api/WEB_GB/taxon-products-by-slug/brands?limit=1&page=2', [], [], self::CONTENT_TYPE_HEADER);
$this->client->request('GET', '/shop-api/WEB_GB/taxon-products/by-slug/brands?limit=1&page=2', [], [], self::CONTENT_TYPE_HEADER);
$response = $this->client->getResponse();

$this->assertResponse($response, 'product/limited_product_list_page_by_slug_response', Response::HTTP_OK);
Expand All @@ -68,7 +68,7 @@ public function it_shows_sorted_product_list(): void
{
$this->loadFixturesFromFiles(['shop.yml']);

$this->client->request('GET', '/shop-api/WEB_GB/taxon-products-by-slug/x-man?sorting[createdAt]=desc', [], [], self::CONTENT_TYPE_HEADER);
$this->client->request('GET', '/shop-api/WEB_GB/taxon-products/by-slug/x-man?sorting[createdAt]=desc', [], [], self::CONTENT_TYPE_HEADER);
$response = $this->client->getResponse();

$this->assertResponse($response, 'product/product_list_page_by_slug_response', Response::HTTP_OK);
Expand All @@ -81,7 +81,7 @@ public function it_expose_only_some_of_products_in_the_list(): void
{
$this->loadFixturesFromFiles(['shop.yml']);

$this->client->request('GET', '/shop-api/WEB_GB/taxon-products-by-slug/x-man?criteria[search][value]=Logans+Hat', [], [], self::CONTENT_TYPE_HEADER);
$this->client->request('GET', '/shop-api/WEB_GB/taxon-products/by-slug/x-man?criteria[search][value]=Logans+Hat', [], [], self::CONTENT_TYPE_HEADER);
$response = $this->client->getResponse();

$this->assertResponse($response, 'product/product_list_page_by_slug_response', Response::HTTP_OK);
Expand All @@ -94,7 +94,7 @@ public function it_does_not_show_product_catalog_by_slug_in_non_existent_channel
{
$this->loadFixturesFromFiles(['shop.yml']);

$this->client->request('GET', '/shop-api/SPACE_KLINGON/taxon-products-by-slug/brands', [], [], self::CONTENT_TYPE_HEADER);
$this->client->request('GET', '/shop-api/SPACE_KLINGON/taxon-products/by-slug/brands', [], [], self::CONTENT_TYPE_HEADER);
$response = $this->client->getResponse();

$this->assertResponse($response, 'channel_has_not_been_found_response', Response::HTTP_NOT_FOUND);
Expand Down
Loading

0 comments on commit 3d06a4d

Please sign in to comment.