Skip to content

Commit

Permalink
fix: account for refunds in exec ed 2u redemption flow
Browse files Browse the repository at this point in the history
  • Loading branch information
adamstankiewicz committed Mar 7, 2023
1 parent 0fc5040 commit 3a61592
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
35 changes: 35 additions & 0 deletions ecommerce/extensions/executive_education_2u/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
from ecommerce.extensions.executive_education_2u.constants import ExecutiveEducation2UCheckoutFailureReason
from ecommerce.extensions.executive_education_2u.utils import get_previous_order_for_user
from ecommerce.extensions.fulfillment.status import ORDER
from ecommerce.extensions.refund.status import REFUND
from ecommerce.extensions.refund.tests.factories import RefundFactory
from ecommerce.extensions.test import factories
from ecommerce.tests.mixins import JwtMixin
from ecommerce.tests.testcases import TestCase
Expand Down Expand Up @@ -130,6 +132,39 @@ def test_begin_checkout_has_previous_order_redirect_to_receipt_page(self):
)
self.assertEqual(response.headers['Location'], expected_redirect_url)

@mock.patch('ecommerce.enterprise.conditions.catalog_contains_course_runs')
@mock.patch('ecommerce.enterprise.conditions.get_course_info_from_catalog')
@mock.patch('ecommerce.extensions.executive_education_2u.views.get_learner_portal_url')
def test_begin_checkout_has_previous_refunded_order_redirect_to_lp(
self,
mock_get_learner_portal_url,
mock_get_course_info_from_catalog,
mock_catalog_contains_course_runs
):
mock_get_learner_portal_url.return_value = self.learner_portal_url
product = self._create_product(is_exec_ed_2u_product=True)
sku = product.stockrecords.first().partner_sku
self._create_enterprise_offer()

order = OrderFactory(user=self.user)
OrderLineFactory(order=order, product=product, partner_sku=sku)
RefundFactory(order=order, user=self.user, status=REFUND.COMPLETE)

mock_get_course_info_from_catalog.return_value = {
'key': product.attr.UUID
}
mock_catalog_contains_course_runs.return_value = True

response = self.client.get(self.checkout_path, {'sku': sku})
self.assertEqual(response.status_code, status.HTTP_302_FOUND)

expected_query_params = {
'course_uuid': product.attr.UUID,
'sku': sku
}
expected_redirect_url = f'{self.learner_portal_url}/executive-education-2u?{urlencode(expected_query_params)}'
self.assertEqual(response.headers['Location'], expected_redirect_url)

@mock.patch('ecommerce.enterprise.conditions.catalog_contains_course_runs')
@mock.patch('ecommerce.enterprise.conditions.get_course_info_from_catalog')
@mock.patch('ecommerce.extensions.executive_education_2u.views.get_learner_portal_url')
Expand Down
6 changes: 4 additions & 2 deletions ecommerce/extensions/executive_education_2u/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ def get_executive_education_2u_product(partner, sku):


def get_previous_order_for_user(user, product):
# TODO: figure out if users can place orders multiple times
return Order.objects.filter(user=user, lines__product=product).first()
"""
Find previous non-refunded order for product from user.
"""
return Order.objects.prefetch_related('refunds').filter(user=user, lines__product=product, refunds__isnull=True).first()


def get_learner_portal_url(request):
Expand Down
2 changes: 1 addition & 1 deletion ecommerce/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@
# Cache enterprise response from Enterprise API.
ENTERPRISE_API_CACHE_TIMEOUT = 300 # Value is in seconds

ENTERPRISE_CATALOG_SERVICE_URL = 'http://localhost:18160/'
ENTERPRISE_CATALOG_SERVICE_URL = 'http://enterprise.catalog.app:18160/'

ENTERPRISE_ANALYTICS_API_URL = 'http://localhost:19001'

Expand Down

0 comments on commit 3a61592

Please sign in to comment.