Skip to content

Commit

Permalink
fix: Updates financial identifier validation to meet 00k criteria
Browse files Browse the repository at this point in the history
  • Loading branch information
brobro10000 committed Jun 27, 2023
1 parent e5ed3da commit 862cd42
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import PROVISIONING_PAGE_TEXT from '../../data/constants';
import ProvisioningFormCustomer from '../ProvisioningFormCustomer';

const { CUSTOMER } = PROVISIONING_PAGE_TEXT.FORM;
const testFinancialLinkage = '0000abc12a332c1444';
const testFinancialLinkage = '00k0abc12a332c1444';
const ProvisioningFormCustomerWrapper = ({
value = initialStateValue,
}) => (
Expand Down
2 changes: 1 addition & 1 deletion src/Configuration/Provisioning/data/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const PROVISIONING_PAGE_TEXT = {
FINANCIAL_IDENTIFIER: {
TITLE: 'Opportunity Product',
ERROR: {
validity: 'Invalid format. Must be 18 characters long, alphanumeric and start with a number.',
validity: 'Invalid format. Must be 18 characters long, alphanumeric and start with \'00k\'.',
emptyField: 'Please enter a valid opportunity product.',
},
},
Expand Down
8 changes: 4 additions & 4 deletions src/Configuration/testData/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export const sampleMultiplePolicyFormData = {
},
],
enterpriseUUID: uuidv4(),
financialIdentifier: '0abc1230abc1234321',
financialIdentifier: '00kc1230abc1234321',
startDate: '2023-04-18',
endDate: '2023-04-21',
internalOnly: 'Yes',
Expand All @@ -163,7 +163,7 @@ export const sampleSinglePolicyPredefinedCatalogQueryFormData = {
},
],
enterpriseUUID: uuidv4(),
financialIdentifier: '0abc1230abc1234321',
financialIdentifier: '00kc1230abc1234321',
startDate: '2023-04-18',
endDate: '2023-04-21',
internalOnly: 'No',
Expand Down Expand Up @@ -195,7 +195,7 @@ export const sampleSinglePolicyCustomCatalogQueryFormData = {
},
],
enterpriseUUID: 'abc',
financialIdentifier: '0abc1230abc1234321',
financialIdentifier: '00kc1230abc1234321',
startDate: '2023-04-06',
endDate: '2023-04-27',
internalOnly: 'Yes',
Expand Down Expand Up @@ -227,7 +227,7 @@ export const sampleSingleEmptyData = {
},
],
enterpriseUUID: 'abc',
financialIdentifier: '0abc1230abc1234321',
financialIdentifier: '00kc1230abc1234321',
startDate: '2023-04-06',
endDate: '2023-04-27',
internalOnly: 'Yes',
Expand Down
15 changes: 13 additions & 2 deletions src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const EMAIL_REGEX = '^[a-zA-Z0-9\'!#$&*._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$';
const USERNAME_REGEX = '^[\\w.@_+-]+$';
const LMS_USER_ID_REGEX = '^(?!0)[0-9]+$';
const DIGITS_ONLY_REGEX = /^(?!0\d)[1-9]\d*(?<!\.)$/;
const OPPORTUNITY_PRODUCT_REGEX = /^\d{1}(?:[0-9A-Za-z]{1,17})?$/;

export const formatDate = (date) => {
if (date) {
Expand Down Expand Up @@ -43,7 +42,19 @@ export const isValidCourseID = (value) => Boolean(value && value.match(COURSE_ID

export const isWholeDollarAmount = (value) => Boolean(value && value.match(DIGITS_ONLY_REGEX));

export const isValidOpportunityProduct = (value) => Boolean(value && value.match(OPPORTUNITY_PRODUCT_REGEX));
// Opportunity Product must begin with 00k and be 18 alphanumeric characters long
export const isValidOpportunityProduct = value => {
if (value?.length <= 2) {
return Boolean(value && value.match(/^[0]{1,2}$/));
}
if (value.length === 3) {
return Boolean(value && value.match(/^[0]{2}k$/));
}
if (value.length > 3 || value.length < 19) {
return Boolean(value && value.match(/^[0]{2}k([0-9A-Za-z]{1,15})$/));
}
return false;
};

export function sort(firstElement, secondElement, key, direction) {
const directionIsAsc = direction === 'asc';
Expand Down

0 comments on commit 862cd42

Please sign in to comment.