diff --git a/src/Resources/config/validation/AddProductReviewByCodeRequest.xml b/src/Resources/config/validation/AddProductReviewByCodeRequest.xml new file mode 100644 index 000000000..cc46d8825 --- /dev/null +++ b/src/Resources/config/validation/AddProductReviewByCodeRequest.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Resources/config/validation/AddProductReviewBySlugRequest.xml b/src/Resources/config/validation/AddProductReviewBySlugRequest.xml new file mode 100644 index 000000000..0f1c136d9 --- /dev/null +++ b/src/Resources/config/validation/AddProductReviewBySlugRequest.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/Controller/ProductAddReviewByCodeApiTest.php b/tests/Controller/ProductAddReviewByCodeApiTest.php index 29176a95e..408947229 100644 --- a/tests/Controller/ProductAddReviewByCodeApiTest.php +++ b/tests/Controller/ProductAddReviewByCodeApiTest.php @@ -18,7 +18,7 @@ public function it_adds_review_to_product() $this->loadFixturesFromFiles(['shop.yml']); $data = - <<assertResponse($response, 'channel_has_not_been_found_response', Response::HTTP_NOT_FOUND); } + + /** + * @test + */ + public function it_does_not_allow_to_add_review_when_rating_is_out_of_bounds() + { + $this->loadFixturesFromFiles(['channel.yml', 'shop.yml']); + + $data = +<<client->request('POST', '/shop-api/WEB_GB/products/LOGAN_MUG_CODE/reviews', [], [], self::$acceptAndContentTypeHeader, $data); + + $response = $this->client->getResponse(); + $this->assertResponse($response, 'reviews/add_review_failed_rating', Response::HTTP_BAD_REQUEST); + } + + /** + * @test + */ + public function it_does_not_allow_to_add_review_when_email_is_not_valid() + { + $this->loadFixturesFromFiles(['channel.yml', 'shop.yml']); + + $data = +<<client->request('POST', '/shop-api/WEB_GB/products/LOGAN_MUG_CODE/reviews', [], [], self::$acceptAndContentTypeHeader, $data); + + $response = $this->client->getResponse(); + $this->assertResponse($response, 'reviews/add_review_failed_email', Response::HTTP_BAD_REQUEST); + } } diff --git a/tests/Controller/ProductAddReviewBySlugApiTest.php b/tests/Controller/ProductAddReviewBySlugApiTest.php index 0492ad1fb..221c04b93 100644 --- a/tests/Controller/ProductAddReviewBySlugApiTest.php +++ b/tests/Controller/ProductAddReviewBySlugApiTest.php @@ -75,4 +75,50 @@ public function it_does_not_allow_to_add_product_review_by_slug_in_non_existent_ $this->assertResponse($response, 'channel_has_not_been_found_response', Response::HTTP_NOT_FOUND); } + + /** + * @test + */ + public function it_does_not_allow_to_add_review_when_rating_is_out_of_bounds() + { + $this->loadFixturesFromFiles(['channel.yml', 'shop.yml']); + + $data = +<<client->request('POST', '/shop-api/WEB_GB/product-reviews-by-slug/mug', [], [], self::$acceptAndContentTypeHeader, $data); + + $response = $this->client->getResponse(); + $this->assertResponse($response, 'reviews/add_review_failed_rating', Response::HTTP_BAD_REQUEST); + } + + /** + * @test + */ + public function it_does_not_allow_to_add_review_when_rating_email_is_not_valid() + { + $this->loadFixturesFromFiles(['channel.yml', 'shop.yml']); + + $data = +<<client->request('POST', '/shop-api/WEB_GB/product-reviews-by-slug/mug', [], [], self::$acceptAndContentTypeHeader, $data); + + $response = $this->client->getResponse(); + $this->assertResponse($response, 'reviews/add_review_failed_email', Response::HTTP_BAD_REQUEST); + } } diff --git a/tests/DependencyInjection/ConfigurationTest.php b/tests/DependencyInjection/ConfigurationTest.php index dc4b7ca7f..1d451ea7d 100644 --- a/tests/DependencyInjection/ConfigurationTest.php +++ b/tests/DependencyInjection/ConfigurationTest.php @@ -63,7 +63,7 @@ public function it_has_view_classes(): void 'page_links' => View\PageLinksView::class, 'payment' => View\PaymentView::class, 'payment_method' => View\PaymentMethodView::class, - 'placed_order' => View\PlacedOrderView::class, + 'placed_order' => View\PlacedOrderView::class, 'price' => View\PriceView::class, 'product' => View\ProductView::class, 'product_attribute_value' => View\ProductAttributeValueView::class, diff --git a/tests/Responses/Expected/reviews/add_review_failed_email.json b/tests/Responses/Expected/reviews/add_review_failed_email.json new file mode 100644 index 000000000..f33026a6a --- /dev/null +++ b/tests/Responses/Expected/reviews/add_review_failed_email.json @@ -0,0 +1,9 @@ +{ + "code": 400, + "message": "Validation failed", + "errors": { + "email": [ + "This value is not a valid email address." + ] + } +} diff --git a/tests/Responses/Expected/reviews/add_review_failed_rating.json b/tests/Responses/Expected/reviews/add_review_failed_rating.json new file mode 100644 index 000000000..cad1309f3 --- /dev/null +++ b/tests/Responses/Expected/reviews/add_review_failed_rating.json @@ -0,0 +1,9 @@ +{ + "code": 400, + "message": "Validation failed", + "errors": { + "rating": [ + "This value should be 5 or less." + ] + } +}