-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
fix(medusa): discounts service create validates against at-least 1 region #2729
Conversation
🦋 Changeset detectedLatest commit: dbe2524 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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.
Very good, only minor comments 🚀
packages/medusa/src/api/routes/admin/discounts/__tests__/create-discount.js
Outdated
Show resolved
Hide resolved
packages/medusa/src/api/routes/admin/discounts/__tests__/create-discount.js
Outdated
Show resolved
Hide resolved
@riqwan can I get you to add a description on the PR and link the linear issue the way I sent you :) |
b156e44
to
aac7794
Compare
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 last comment and one thing to look at. We should probably update the service method that creates the discounts to enforce at least one. At the moment it accepts optional regions properties but it might be wrong too. Could you check please?
packages/medusa/src/api/routes/admin/discounts/__tests__/create-discount.js
Outdated
Show resolved
Hide resolved
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.
LGTM, few minor comments left and I think we are good to go ahah @olivermrbl do you want to run a review?
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.
LGTM 🎉 one last comment ahah
A discount should always be associated to atleast 1 region - we validate it against the region in the cart service. Adding a request parameter validation to pass in atleast one regionID in an array of regions will ensure that regionID will be validated as a part of the discount service and fail if its not a valid region ID.
…s regions inclusion and validity
4bd126d
to
c1cdb80
Compare
2577562
to
5240972
Compare
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.
LGTM 🎉 very nice boy scoot session included 💪
@riqwan I suggest to also wait the approval from @olivermrbl to have a second pair of eyes |
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.
Really solid work @riqwan! Don't have anything to add 🥳
When a discount is updated with an empty regions array, the discount ends up in a state with no regions.
Ideally, we would add a check similar to this PR. Not super urgent, but feel free to create a Linear issue and tackle that too 💪
What do we do about existing discounts that have no region?
I don't think we have to do anything. Worst case, the invalid discounts throw a 400 + sends an appropriate error message when applied to carts.
What:
Why:
A discount is validated against a region while being added to a cart. Any discount that is applied therefore needs to be associated with a valid region.
How:
As a first step, we introduce a validation into the discount create service. With this PR, discounts will always be associated with a region on creation of a discount.
There are some cases we need to handle:
Testing:
Unit tests:
Integration tests:
FIXES CORE-873