-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #388 Adding validation to the
AddProductReview
endpoint (ma…
…mazu) This PR was merged into the 1.0-dev branch. Discussion ---------- In Sylius product reviews have to have a rating between 0 and 5. Anything else is out of range. I added validation. This should also close #160. Commits ------- 5c4e67f Added validation for the add product view 227fbf8 Added validation for product review 243f349 Fixed tests 7641fb6 Fixed typos aef4053 Merge branch 'master' into status 98932c7 Moved the tests to the correct controller dc54ce5 Codestyle
- Loading branch information
Showing
7 changed files
with
182 additions
and
2 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
src/Resources/config/validation/AddProductReviewByCodeRequest.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<!-- | ||
This file is part of the Sylius package. | ||
(c) Paweł Jędrzejewski | ||
For the full copyright and license information, please view the LICENSE | ||
file that was distributed with this source code. | ||
--> | ||
|
||
<constraint-mapping xmlns="http://symfony.com/schema/dic/constraint-mapping" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping http://symfony.com/schema/dic/services/constraint-mapping-1.0.xsd"> | ||
<class name="Sylius\ShopApiPlugin\Request\AddProductReviewByCodeRequest"> | ||
<property name="title"> | ||
<constraint name="NotNull" /> | ||
</property> | ||
<property name="rating"> | ||
<constraint name="Type"> | ||
<option name="type">integer</option> | ||
</constraint> | ||
<constraint name="Range"> | ||
<option name="min">0</option> | ||
<option name="max">5</option> | ||
</constraint> | ||
</property> | ||
<property name="email"> | ||
<constraint name="Email" /> | ||
</property> | ||
</class> | ||
</constraint-mapping> |
34 changes: 34 additions & 0 deletions
34
src/Resources/config/validation/AddProductReviewBySlugRequest.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<!-- | ||
This file is part of the Sylius package. | ||
(c) Paweł Jędrzejewski | ||
For the full copyright and license information, please view the LICENSE | ||
file that was distributed with this source code. | ||
--> | ||
|
||
<constraint-mapping xmlns="http://symfony.com/schema/dic/constraint-mapping" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping http://symfony.com/schema/dic/services/constraint-mapping-1.0.xsd"> | ||
<class name="Sylius\ShopApiPlugin\Request\AddProductReviewBySlugRequest"> | ||
<property name="title"> | ||
<constraint name="NotNull" /> | ||
</property> | ||
<property name="rating"> | ||
<constraint name="Type"> | ||
<option name="type">integer</option> | ||
</constraint> | ||
<constraint name="Range"> | ||
<option name="min">0</option> | ||
<option name="max">5</option> | ||
</constraint> | ||
</property> | ||
<property name="email"> | ||
<constraint name="Email" /> | ||
</property> | ||
</class> | ||
</constraint-mapping> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
tests/Responses/Expected/reviews/add_review_failed_email.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"code": 400, | ||
"message": "Validation failed", | ||
"errors": { | ||
"email": [ | ||
"This value is not a valid email address." | ||
] | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
tests/Responses/Expected/reviews/add_review_failed_rating.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"code": 400, | ||
"message": "Validation failed", | ||
"errors": { | ||
"rating": [ | ||
"This value should be 5 or less." | ||
] | ||
} | ||
} |