Skip to content
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

Validate complete order request #599

Merged
merged 2 commits into from
Nov 23, 2019

Conversation

kayue
Copy link
Contributor

@kayue kayue commented Nov 11, 2019

The first step to fix #598 is to perform validation in CompleteOrderAction

@kayue kayue requested a review from a team as a code owner November 11, 2019 10:44
@mamazu
Copy link
Member

mamazu commented Nov 11, 2019

Thanks for your contribution to ShopAPI. I have a question about your pull request: What does it validate at the moment, if you haven't have any validation specified.

@kayue
Copy link
Contributor Author

kayue commented Nov 12, 2019

@mamazu Ideally it should re-validate inventory availability, which can be implemented later.

Nevertheless, Sylius is meant to be extendable, even the ShopAPI doesn't have any validation specified, it should still perform validation to allower developer to add custom validator.

@kayue
Copy link
Contributor Author

kayue commented Nov 12, 2019

Also due to inconsistent implementation in action class, error is being return in multiple different formats.

For example, invalid cart token, it returns proper error 400 in PutItemToCartAction:

{
  "code": 400,
  "message": "Validation failed",
  "errors": {
    "token": [
      "Cart does not exist."
    ]
  }
}

However, in CompleteOrderAction it returns error 500 due to lack of validation, which needs to be fixed.

{
  "code": 500,
  "message": "Order with ca5ac343-f09d-4cf0-8d34-374d77cd2ca91 token has not been found."
}

In SummarizeAction it returns error 404

{
  "code": 404,
  "message": "Cart with given id does not exists"
}

@mamazu
Copy link
Member

mamazu commented Nov 12, 2019

Currently as you found the order complete doesn't validate anything and therefore only asserts that the cart is there (which then will cause an error => 500) We should definitely add the same validators as the other endpoints have as well. Like CartExists and so on.

@lchrusciel
Copy link
Member

Hey @kayue,

are you willing to add test for this case?

OrderInterface $order,
FactoryInterface $stateMachineFactory,
StateMachineInterface $stateMachine,
ExecutionContextInterface $context
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ExecutionContextInterface $context
ExecutionContextInterface $context

@lchrusciel lchrusciel merged commit 8a7a170 into Sylius:master Nov 23, 2019
@lchrusciel
Copy link
Member

lchrusciel commented Nov 23, 2019

Thanks, Ka and Max! 🥇

@kayue kayue deleted the validate-complete-checkout branch November 25, 2019 07:37
@kayue
Copy link
Contributor Author

kayue commented Nov 25, 2019

Thanks @lchrusciel for adding the tests. I didn't know what to test but now I learned.

@lchrusciel
Copy link
Member

All credits to @mamazu. I just asked him for help ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CompleteOrderRequest should check for customer object
3 participants