-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[API] Test not providing required fields during registration #12811
[API] Test not providing required fields during registration #12811
Conversation
88fb3c0
to
02d9428
Compare
02d9428
to
de381ee
Compare
src/Sylius/Bundle/ApiBundle/Serializer/CommandOperationDenormalizer.php
Outdated
Show resolved
Hide resolved
src/Sylius/Bundle/ApiBundle/Serializer/CommandOperationDenormalizer.php
Outdated
Show resolved
Hide resolved
@@ -27,6 +27,7 @@ api_platform: | |||
SM\SMException: 422 | |||
Sylius\Bundle\ApiBundle\Exception\CannotRemoveCurrentlyLoggedInUser: 422 | |||
Sylius\Bundle\ApiBundle\Exception\ShippingMethodCannotBeRemoved: 422 | |||
Symfony\Component\Serializer\Exception\MissingConstructorArgumentsException: 400 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it needed? And if so, do we have exactly the same error structure as in normal missing field validation errors?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The goal of the change was to have a different error code in the response than 500
. I'm not super-devoted to this code, but I suppose it should be 4**
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
52854b2
to
09e5c23
Compare
09e5c23
to
31aba0f
Compare
src/Sylius/Bundle/ApiBundle/Serializer/CommandOperationNormalizer.php
Outdated
Show resolved
Hide resolved
src/Sylius/Bundle/ApiBundle/Serializer/CommandOperationDenormalizer.php
Outdated
Show resolved
Hide resolved
src/Sylius/Bundle/ApiBundle/Serializer/CommandOperationNormalizer.php
Outdated
Show resolved
Hide resolved
985b790
to
c535148
Compare
/** | ||
* @experimental | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One liner maybe? 🙂 And same for next class.
Scenario: Trying to register a new account without providing required fields | ||
When I want to register a new account | ||
And I specify the email as "goodman@gmail.com" | ||
And I specify the password as "heisenberg" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️
*/ | ||
public function iShouldBeNotifiedThatFieldHaveToBeProvided(string ...$fields): void | ||
{ | ||
$fields = $this->convertElementsToCamelCase($fields); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could create camelCaseTransformer 😄
|
||
private function getResponseContent(): array | ||
{ | ||
return json_decode($this->client->getResponse()->getContent(), true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about adding this method to the test client?
Thank you, Mateusz! 🎉 |
…default value (GSadee) This PR was merged into the 1.9 branch. Discussion ---------- | Q | A | --------------- | ----- | Branch? | 1.9 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Related tickets | fixes #12811 | License | MIT Fixes tests on 1.10 and master branches, where we test [RegisterShopUser](https://github.com/Sylius/Sylius/blob/1.10/src/Sylius/Bundle/ApiBundle/Command/RegisterShopUser.php#L69) that has new not nullable argument with a default value. Failing test: https://github.com/Sylius/Sylius/runs/3122767036?check_suite_focus=true#step:18:75 Commits ------- 80836cf [API] Allow creation of commands with no arguments with a default value
… to populate (GSadee) This PR was merged into the 1.10 branch. Discussion ---------- | Q | A | --------------- | ----- | Branch? | 1.10 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Related tickets | fixes #12811 | License | MIT <!-- - Bug fixes must be submitted against the 1.9 or 1.10 branch (the lowest possible) - Features and deprecations must be submitted against the master branch - Make sure that the correct base branch is set To be sure you are not breaking any Backward Compatibilities, check the documentation: https://docs.sylius.com/en/latest/book/organization/backward-compatibility-promise.html --> Commits ------- 56f14d4 [API] Do not check command arguments if there is an object to populate f163dd4 [API] Use proper command bus in ApiBundle tests c880876 [API] Fix tests for PHP 8.0
The solution allows receiving proper, more explainable and less technical responses where some fields are not provided in the API request. Denormalizer detects if there are any missing required fields for the request input class and throws an exception. In fact, the same thing happens inside the API Platform, but the exception message is poor - and that's the reason we should change it. A normalizer is unfortunately needed (despite the exception mapping), to provide a proper response code in the response body. Maybe it could also be done in a more generic way 🖖
I'm not sure either it should be a bug fix or not... I feel that it can, as it solves a functionality for existing endpoints as well, but I'm not 100% sure about it 😄 🚀