[API] Test not providing required fields during registration#12811
Merged
GSadee merged 5 commits intoJul 21, 2021
Merged
Conversation
88fb3c0 to
02d9428
Compare
02d9428 to
de381ee
Compare
GSadee
reviewed
Jul 19, 2021
lchrusciel
reviewed
Jul 19, 2021
| SM\SMException: 422 | ||
| Sylius\Bundle\ApiBundle\Exception\CannotRemoveCurrentlyLoggedInUser: 422 | ||
| Sylius\Bundle\ApiBundle\Exception\ShippingMethodCannotBeRemoved: 422 | ||
| Symfony\Component\Serializer\Exception\MissingConstructorArgumentsException: 400 |
Contributor
There was a problem hiding this comment.
Is it needed? And if so, do we have exactly the same error structure as in normal missing field validation errors?
Contributor
Author
There was a problem hiding this comment.
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**
Contributor
52854b2 to
09e5c23
Compare
09e5c23 to
31aba0f
Compare
GSadee
approved these changes
Jul 20, 2021
AdamKasp
approved these changes
Jul 20, 2021
985b790 to
c535148
Compare
arti0090
approved these changes
Jul 20, 2021
Comment on lines
+20
to
+22
| /** | ||
| * @experimental | ||
| */ |
Contributor
There was a problem hiding this comment.
One liner maybe? 🙂 And same for next class.
Arminek
approved these changes
Jul 20, 2021
| 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 "[email protected]" | ||
| And I specify the password as "heisenberg" |
| */ | ||
| public function iShouldBeNotifiedThatFieldHaveToBeProvided(string ...$fields): void | ||
| { | ||
| $fields = $this->convertElementsToCamelCase($fields); |
Contributor
There was a problem hiding this comment.
We could create camelCaseTransformer 😄
|
|
||
| private function getResponseContent(): array | ||
| { | ||
| return json_decode($this->client->getResponse()->getContent(), true); |
Contributor
There was a problem hiding this comment.
How about adding this method to the test client?
lchrusciel
approved these changes
Jul 20, 2021
Member
|
Thank you, Mateusz! 🎉 |
Zales0123
added a commit
that referenced
this pull request
Jul 21, 2021
…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
GSadee
added a commit
that referenced
this pull request
Jul 22, 2021
… 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
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

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 😄 🚀