Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
feat: Updates opportunity line item regex and tests (#3996)
Browse files Browse the repository at this point in the history
  • Loading branch information
brobro10000 authored Jul 10, 2023
1 parent a4766a5 commit 3b1fcb0
Show file tree
Hide file tree
Showing 12 changed files with 30 additions and 30 deletions.
4 changes: 2 additions & 2 deletions ecommerce/enterprise/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
# potential edge case).
ENTERPRISE_SALES_FORCE_ID_REGEX = r'^006[a-zA-Z0-9]{15}$|^none$'

# Salesforce Opportunity Opportunity Line item must be 18 alphanumeric characters
# Salesforce 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'^00k[a-zA-Z0-9]{15}$|^none$'
2 changes: 1 addition & 1 deletion ecommerce/enterprise/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def clean_salesforce_opportunity_line_item(self):
if not re.match(ENTERPRISE_SALESFORCE_OPPORTUNITY_LINE_ITEM_REGEX, salesforce_opportunity_line_item):
self.add_error(
'salesforce_opportunity_line_item',
_('The Salesforce Opportunity Line Item must be 18 alphanumeric characters and begin with a number.')
_('The Salesforce Opportunity Line Item must be 18 alphanumeric characters and begin with \'00k\'.')
)
return self.cleaned_data.get('salesforce_opportunity_line_item')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 7 additions & 7 deletions ecommerce/enterprise/tests/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -496,18 +496,18 @@ 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',
'The Salesforce Opportunity Line Item must be 18 alphanumeric characters and begin with a number.'),
'The Salesforce Opportunity Line Item must be 18 alphanumeric characters and begin with \'00k\'.'),
('006ABCDE01234',
'The Salesforce Opportunity Line Item must be 18 alphanumeric characters and begin with a number.'),
'The Salesforce Opportunity Line Item must be 18 alphanumeric characters and begin with \'00k\'.'),
('a07ABCDE0123456789',
'The Salesforce Opportunity Line Item must be 18 alphanumeric characters and begin with a number.'),
'The Salesforce Opportunity Line Item must be 18 alphanumeric characters and begin with \'00k\'.'),
('006ABCDE0 12345678',
'The Salesforce Opportunity Line Item must be 18 alphanumeric characters and begin with a number.'),
'The Salesforce Opportunity Line Item must be 18 alphanumeric characters and begin with \'00k\'.'),
)
@ddt.unpack
def test_salesforce_opportunity_line_item(self, salesforce_opportunity_line_item, expected_error):
Expand Down
4 changes: 2 additions & 2 deletions ecommerce/enterprise/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion ecommerce/extensions/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1697,7 +1697,7 @@ def validate_salesforce_opportunity_line_item_format(self):
re.match(ENTERPRISE_SALESFORCE_OPPORTUNITY_LINE_ITEM_REGEX, salesforce_opportunity_line_item):
raise ValidationError({
'salesforce_opportunity_line_item':
'Salesforce Opportunity Line Item must be 18 alphanumeric characters and begin with a number.'
'Salesforce Opportunity Line Item must be 18 alphanumeric characters and begin with \'00k\'.'
})


Expand Down
4 changes: 2 additions & 2 deletions ecommerce/extensions/api/v2/tests/views/test_coupons.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand Down Expand Up @@ -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):
"""
Expand Down
16 changes: 8 additions & 8 deletions ecommerce/extensions/api/v2/tests/views/test_enterprise.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -458,21 +458,21 @@ 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.'),
(
'006ABCDE012345678123143',
400,
'Salesforce Opportunity Line Item must be 18 alphanumeric characters and begin with a number.'
'Salesforce Opportunity Line Item must be 18 alphanumeric characters and begin with \'00k\'.'
),
('006ABCDE01234', 400,
'Salesforce Opportunity Line Item must be 18 alphanumeric characters and begin with a number.'),
('a07ABCDE0123456789', 400,
'Salesforce Opportunity Line Item must be 18 alphanumeric characters and begin with a number.'),
'Salesforce Opportunity Line Item must be 18 alphanumeric characters and begin with \'00k\'.'),
('a0KABCDE0123456789', 400,
'Salesforce Opportunity Line Item must be 18 alphanumeric characters and begin with \'00k\'.'),
('006ABCDE0 12345678', 400,
'Salesforce Opportunity Line Item must be 18 alphanumeric characters and begin with a number.'),
'Salesforce Opportunity Line Item must be 18 alphanumeric characters and begin with \'00k\'.'),
)
@ddt.unpack
def test_salesforce_opportunity_line_item(self, salesforce_opportunity_line_item, expected_status_code, error_mesg):
Expand Down
4 changes: 2 additions & 2 deletions ecommerce/extensions/api/v2/views/orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion ecommerce/static/js/test/mock_data/coupons.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
4 changes: 2 additions & 2 deletions ecommerce/static/js/utils/validation_patterns.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ define([
});

_.extend(Backbone.Validation.patterns, {
salesforce_opportunity_line_item: /^[0-9]{1}[a-zA-Z0-9]{17}$|^none$/
salesforce_opportunity_line_item: /^00k[a-zA-Z0-9]{15}$|^none$/
});

_.extend(Backbone.Validation.messages, {
salesforce_opportunity_line_item: gettext(
'Salesforce Opportunity Line Item must be 18 alphanumeric characters and begin with a number'
'Salesforce Opportunity Line Item must be 18 alphanumeric characters and begin with \'00k\''
)
});
}
Expand Down

0 comments on commit 3b1fcb0

Please sign in to comment.