mitodl / mitxpro

BSD 3-Clause "New" or "Revised" License
12 stars 2 forks source link

Enable fields for coupon and b2bcoupon to be editable #2951

Closed mudassir-hafeez closed 4 months ago

mudassir-hafeez commented 4 months ago

What are the relevant tickets?

#3990

Description (What does it do?)

This PR fixes #3990 by enabling fields for coupon and b2bcoupon to be editable, and fixes name collision.

Screenshots (if appropriate):

Steps to Reproduce(Coupon name collision)

  1. Create a coupon code for a regular checkout
    • Or, Use /ecommerce/admin in your xPRO app and generate a coupon through the form
  2. Get the coupon name(not coupon code) of the above created coupon and use it as a coupon code in B2BCoupon creation.
  3. Try to redeem above created B2B coupon through /ecommerce/bulk
  4. You will see an exception about the unique constraint failure in the Coupon Payment Name.

How can this be tested?

  1. Verify that the fields in the Coupon and B2B Coupon models are editable.
  2. Along with that, test, if there is no unique constraint failure in the Coupon Payment Name.
    • Create a coupon code for a regular checkout
      • you can use /ecommerce/admin in your xPRO app and generate a coupon through the form.
    • Create a coupon in B2BCoupon with the same Coupon Payment Name/Coupon name(not coupon code) as above.
    • Try to redeem above created B2B coupon through /ecommerce/bulk
    • It should be redeemed without any exception.

For the second point, ensure that completing a B2B order is tested with different discount percentages applied to the B2BCoupon:

Additional Context

arslanashraf7 commented 4 months ago

@mudassir-hafeez Can you also add a test that checks the use case(s) of editing the same coupon? This will help us avoid hitting this bug in the future. e.g.