From 07c575b9570de78c6a21cd3d33e38c0d95988275 Mon Sep 17 00:00:00 2001 From: Hamzah Ullah Date: Fri, 30 Jun 2023 15:37:49 +0000 Subject: [PATCH] feat: Updates opportunity line item regex and tests --- ecommerce/enterprise/constants.py | 2 +- .../management/commands/seed_enterprise_devstack_data.py | 2 +- ecommerce/enterprise/tests/test_forms.py | 6 +++--- ecommerce/enterprise/tests/test_views.py | 4 ++-- ecommerce/extensions/api/v2/tests/views/test_coupons.py | 4 ++-- ecommerce/extensions/api/v2/tests/views/test_enterprise.py | 6 +++--- ecommerce/extensions/api/v2/views/orders.py | 4 ++-- ecommerce/static/js/test/mock_data/coupons.js | 2 +- .../specs/views/enterprise_coupon_create_edit_view_spec.js | 2 +- ecommerce/static/js/utils/validation_patterns.js | 2 +- 10 files changed, 17 insertions(+), 17 deletions(-) diff --git a/ecommerce/enterprise/constants.py b/ecommerce/enterprise/constants.py index b3912fc1fdc..1eb22861186 100644 --- a/ecommerce/enterprise/constants.py +++ b/ecommerce/enterprise/constants.py @@ -20,4 +20,4 @@ # Salesforce Opportunity Opportunity Line item must be 18 alphanumeric characters # and begin with a number OR be "none" (to accommodate potential edge case). -ENTERPRISE_SALESFORCE_OPPORTUNITY_LINE_ITEM_REGEX = r'^[0-9]{1}[a-zA-Z0-9]{17}$|^none$' +ENTERPRISE_SALESFORCE_OPPORTUNITY_LINE_ITEM_REGEX = r'^00[kK][a-zA-Z0-9]{15}$|^none$' diff --git a/ecommerce/enterprise/management/commands/seed_enterprise_devstack_data.py b/ecommerce/enterprise/management/commands/seed_enterprise_devstack_data.py index 64aed795a4c..ee12f0a0f55 100644 --- a/ecommerce/enterprise/management/commands/seed_enterprise_devstack_data.py +++ b/ecommerce/enterprise/management/commands/seed_enterprise_devstack_data.py @@ -127,7 +127,7 @@ def create_coupon(self, api_client, ecommerce_api_url, enterprise_catalog_api_ur "end_datetime": str(now() + datetime.timedelta(days=10)), "benefit_value": 100, "sales_force_id": '006aaaaaaaaaaaaaaa', - "sales_force_opportunity_line_item": '01aaaaaaaaaaaaaaaa', + "sales_force_opportunity_line_item": '00kaaaaaaaaaaaaaaa', } url = urljoin(f"{ecommerce_api_url}/", "enterprise/coupons/") response = api_client.post(url, json=request_obj) diff --git a/ecommerce/enterprise/tests/test_forms.py b/ecommerce/enterprise/tests/test_forms.py index d339b1ff41c..4991b7c8a7c 100644 --- a/ecommerce/enterprise/tests/test_forms.py +++ b/ecommerce/enterprise/tests/test_forms.py @@ -46,7 +46,7 @@ def generate_data(self, **kwargs): 'contract_discount_value': self.contract_discount_value, 'prepaid_invoice_amount': self.prepaid_invoice_amount, 'sales_force_id': '006abcde0123456789', - 'salesforce_opportunity_line_item': '000abcde9876543210', + 'salesforce_opportunity_line_item': '00kabcde9876543210', 'max_global_applications': 2, 'max_discount': 300, 'max_user_discount': 50, @@ -496,8 +496,8 @@ def _test_salesforce_opportunity_line_item(self, salesforce_opportunity_line_ite @ddt.data( # Valid Cases - ('006abcde0123456789', None), - ('006ABCDE0123456789', None), + ('00kabcde0123456789', None), + ('00KABCDE0123456789', None), ('none', None), # Invalid Cases ('006ABCDE012345678123143', diff --git a/ecommerce/enterprise/tests/test_views.py b/ecommerce/enterprise/tests/test_views.py index de89d8df894..ba228da4506 100644 --- a/ecommerce/enterprise/tests/test_views.py +++ b/ecommerce/enterprise/tests/test_views.py @@ -109,7 +109,7 @@ def test_post(self): 'contract_discount_value': 200, 'prepaid_invoice_amount': 2000, 'sales_force_id': '006abcde0123456789', - 'salesforce_opportunity_line_item': '000abcde9876543210', + 'salesforce_opportunity_line_item': '00kabcde9876543210', 'usage_email_frequency': ConditionalOffer.DAILY } response = self.client.post(self.path, data, follow=False) @@ -131,7 +131,7 @@ def test_post(self): expected_discount_type = 'Absolute' expected_prepaid_invoice_amount = 12345 sales_force_id = '006abcde0123456789' - salesforce_opportunity_line_item = '000abcde9876543210' + salesforce_opportunity_line_item = '00kabcde9876543210' data = { 'enterprise_customer_uuid': expected_ec_uuid, 'enterprise_customer_catalog_uuid': expected_ec_catalog_uuid, diff --git a/ecommerce/extensions/api/v2/tests/views/test_coupons.py b/ecommerce/extensions/api/v2/tests/views/test_coupons.py index 480e742b03e..93739a48c7e 100644 --- a/ecommerce/extensions/api/v2/tests/views/test_coupons.py +++ b/ecommerce/extensions/api/v2/tests/views/test_coupons.py @@ -248,7 +248,7 @@ def setUp(self): 'title': 'Tešt čoupon', 'voucher_type': Voucher.SINGLE_USE, 'sales_force_id': '006ABCDE0123456789', - 'salesforce_opportunity_line_item': '000ABCDE9876543210', + 'salesforce_opportunity_line_item': '00kABCDE9876543210', } self.response = self.get_response('POST', COUPONS_LINK, self.data) self.coupon = Product.objects.get(title=self.data['title']) @@ -697,7 +697,7 @@ def test_update_note(self): self.assertEqual(new_coupon.attr.note, note) @ddt.data( - '006abcde0123456789', 'otherSalesForce', '' + '00kabcde0123456789', 'otherSalesForce', '' ) def test_update_sales_force_id(self, sales_force_id): """ diff --git a/ecommerce/extensions/api/v2/tests/views/test_enterprise.py b/ecommerce/extensions/api/v2/tests/views/test_enterprise.py index 543fd7c576d..987c96d3979 100644 --- a/ecommerce/extensions/api/v2/tests/views/test_enterprise.py +++ b/ecommerce/extensions/api/v2/tests/views/test_enterprise.py @@ -323,7 +323,7 @@ def setUp(self): 'contract_discount_value': '12.35', 'notify_learners': True, 'sales_force_id': '006ABCDE0123456789', - 'salesforce_opportunity_line_item': '000ABCDE9876543210', + 'salesforce_opportunity_line_item': '00kABCDE9876543210', } self.course = CourseFactory(id='course-v1:test-org+course+run', partner=self.partner) @@ -458,8 +458,8 @@ def _test_salesforce_opportunity_line_item_on_update_coupon( self.assertEqual(coupon.attr.salesforce_opportunity_line_item, salesforce_opportunity_line_item) @ddt.data( - ('006abcde0123456789', 200, None), - ('006ABCDE0123456789', 200, None), + ('00kabcde0123456789', 200, None), + ('00KABCDE0123456789', 200, None), ('none', 200, None), (None, 400, 'This field is required.'), ( diff --git a/ecommerce/extensions/api/v2/views/orders.py b/ecommerce/extensions/api/v2/views/orders.py index 7426250d560..17eba2919e5 100644 --- a/ecommerce/extensions/api/v2/views/orders.py +++ b/ecommerce/extensions/api/v2/views/orders.py @@ -125,7 +125,7 @@ class ManualCourseEnrollmentOrderViewSet(EdxOrderPlacementMixin, EnterpriseDisco >>> "discount_percentage": 75.0, >>> "date_placed": '2020-02-11T09:38:47.634561+00:00', # optional param, only for old records. >>> "sales_force_id": '252F0060L00000ppWfu', - >>> "salesforce_opportunity_line_item": 'abcF0060L00000ppWfu', + >>> "salesforce_opportunity_line_item": '00kF0060L00000ppWfu', >>> "mode": 'verified', >>> "enterprise_customer_name": "an-enterprise-customer", >>> "enterprise_customer_uuid": "394a5ce5-6ff4-4b2b-bea1-a273c6920ae1", @@ -153,7 +153,7 @@ class ManualCourseEnrollmentOrderViewSet(EdxOrderPlacementMixin, EnterpriseDisco >>> "discount_percentage": 75.0, >>> "date_placed": '2020-02-11T09:38:47.634561+00:00', >>> "sales_force_id": '252F0060L00000ppWfu', - >>> "salesforce_opportunity_line_item": 'abcF0060L00000ppWfu', + >>> "salesforce_opportunity_line_item": '00kF0060L00000ppWfu', >>> "mode": 'verified', >>> "enterprise_customer_name": "an-enterprise-customer", >>> "enterprise_customer_uuid": "394a5ce5-6ff4-4b2b-bea1-a273c6920ae1", diff --git a/ecommerce/static/js/test/mock_data/coupons.js b/ecommerce/static/js/test/mock_data/coupons.js index 9bf4d670bcc..c6c970ae950 100644 --- a/ecommerce/static/js/test/mock_data/coupons.js +++ b/ecommerce/static/js/test/mock_data/coupons.js @@ -263,7 +263,7 @@ define([], function() { contract_discount_value: 30, prepaid_invoice_amount: 10000, sales_force_id: '006ABCDE0123456789', - salesforce_opportunity_line_item: '000ABCDE9876543210', + salesforce_opportunity_line_item: '00kABCDE9876543210', invoice_type: 'Not-Applicable' }, couponAPIResponseData = { diff --git a/ecommerce/static/js/test/specs/views/enterprise_coupon_create_edit_view_spec.js b/ecommerce/static/js/test/specs/views/enterprise_coupon_create_edit_view_spec.js index a5252d4aea0..d0438aebc6f 100644 --- a/ecommerce/static/js/test/specs/views/enterprise_coupon_create_edit_view_spec.js +++ b/ecommerce/static/js/test/specs/views/enterprise_coupon_create_edit_view_spec.js @@ -44,7 +44,7 @@ define([ it('should submit enterprise coupon form with valid fields', function() { view.$('[name=sales_force_id]').val('006ABCDE0123456789').trigger('change'); - view.$('[name=salesforce_opportunity_line_item]').val('000ABCDE9876543210').trigger('change'); + view.$('[name=salesforce_opportunity_line_item]').val('00kABCDE9876543210').trigger('change'); view.$('[name=contract_discount_value]').val(30).trigger('change'); view.$('[name=prepaid_invoice_amount]').val(10000).trigger('change'); view.$('[name=title]').val('Test Enrollment').trigger('change'); diff --git a/ecommerce/static/js/utils/validation_patterns.js b/ecommerce/static/js/utils/validation_patterns.js index 8ca59992364..f31aeee5d25 100644 --- a/ecommerce/static/js/utils/validation_patterns.js +++ b/ecommerce/static/js/utils/validation_patterns.js @@ -35,7 +35,7 @@ define([ }); _.extend(Backbone.Validation.patterns, { - salesforce_opportunity_line_item: /^[0-9]{1}[a-zA-Z0-9]{17}$|^none$/ + salesforce_opportunity_line_item: /^00[kK][a-zA-Z0-9]{15}$|^none$/ }); _.extend(Backbone.Validation.messages, {