Skip to content

Commit

Permalink
Merge pull request #213 from SalesforceCommerceCloud/fix/fix-unit-tests
Browse files Browse the repository at this point in the history
Fix unit tests
  • Loading branch information
jbachelet committed Dec 19, 2022
2 parents f6f4a66 + 5dc91fe commit 60b5971
Show file tree
Hide file tree
Showing 20 changed files with 11,433 additions and 10,751 deletions.
12 changes: 0 additions & 12 deletions config/default.js
Expand Up @@ -113,18 +113,6 @@ module.exports = {

},

// Define the regular expressions used to govern the siteId / connectedAppId
"connectedAppIdRegEx": {

// Describe the individual regExes used to clean the siteId
"whiteSpace": /\s/g,
"dashes": /-/g,
"doubleUnderscore": /_+/g,
"nonAlphaNumeric": /[^\w_]+/g,
"alphaOnly": /^[a-zA-Z]/g

},

// Describe the collection of available scratchOrg profiles
"sfScratchOrg": {

Expand Down
10 changes: 5 additions & 5 deletions lib/cli-api/_common/_cleanSiteIdForConnectedApp.js
Expand Up @@ -22,16 +22,16 @@ module.exports = function _cleanSiteIdForConnectedApp(siteId) {
output = siteId.trim();

// Next, replace all whitespace found in the site definition
output = output.replace(config.get('connectedAppIdRegEx.whiteSpace'), '');
output = output.replace(new RegExp(/\s/, 'g'), '');

// Next, replace all dashes with an underscore (to try and maintain some consistency)
output = output.replace(config.get('connectedAppIdRegEx.dashes'), '_');
output = output.replace(new RegExp(/-/, 'g'), '_');

// Replace double-underscores until none exist
output = output.replace(config.get('connectedAppIdRegEx.doubleUnderscore'), '_');
output = output.replace(new RegExp(/_+/, 'g'), '_');

// Next, remove all non-alpha-numeric non-underscore characters
output = output.replace(config.get('connectedAppIdRegEx.nonAlphaNumeric'), '');
output = output.replace(new RegExp(/[^\w_]+/, 'g'), '');

// Next, ensure the siteId doesn't end in an underscore
lastCharacter = output.substr((output.length - 1), 1);
Expand All @@ -45,7 +45,7 @@ module.exports = function _cleanSiteIdForConnectedApp(siteId) {
firstCharacter = output.substr(0, 1);

// Create a regular expression to validate the siteId
let thisRegEx = new RegExp(config.get('connectedAppIdRegEx.alphaOnly'));
let thisRegEx = new RegExp(/^[a-zA-Z]/, 'g');

// If the first character is not a letter, replace it and default the firstCharacter with a letter
if (!thisRegEx.test(firstCharacter)) {
Expand Down
21,877 changes: 11,314 additions & 10,563 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -87,7 +87,7 @@
"fs-extra": "^10.0.0",
"generate-password": "^1.6.0",
"jks-js": "^1.0.1",
"jsforce": "^1.10.1",
"jsforce": "^1.11.0",
"jsonwebtoken": "^8.5.1",
"lodash": "^4.17.21",
"mkdirp": "^1.0.4",
Expand All @@ -98,7 +98,7 @@
"recursive-readdir": "^2.2.2",
"save": "^2.4.0",
"sfcc-ci": "~2.7.2",
"sfdx-node": "^3.1.0",
"sfdx-node": "^3.6.1",
"terminal-link": "^2.1.1",
"validate.js": "^0.13.1",
"validator": "^13.7.0",
Expand Down
2 changes: 1 addition & 1 deletion sfdx-project.json
Expand Up @@ -15,5 +15,5 @@
],
"namespace": "",
"sfdcLoginUrl": "https://login.salesforce.com",
"sourceApiVersion": "54.0"
"sourceApiVersion": "56.0"
}
106 changes: 49 additions & 57 deletions src/sfdc/base/main/default/classes/B2CConfigurationManager.cls
Expand Up @@ -21,30 +21,38 @@ public with sharing class B2CConfigurationManager {
// Initialize the output map
output = new Map<String, String>();

// Get the default configuration profile
configurationProfile = [
SELECT Active_Configuration__r.B2C_CRM_Sync_AuthToken_Settings__r.Account_Manager_Url__c,
Active_Configuration__r.B2C_CRM_Sync_AuthToken_Settings__r.Account_Manager_Port__c,
Active_Configuration__r.B2C_CRM_Sync_AuthToken_Settings__r.Account_Manager_Token_Url__c,
Active_Configuration__r.B2C_CRM_Sync_AuthToken_Settings__r.Expiration_in_Minutes__c,
Active_Configuration__r.B2C_CRM_Sync_AuthToken_Settings__r.JWT_Algorithm__c,
Active_Configuration__r.B2C_CRM_Sync_AuthToken_Settings__r.JWT_SFCC_Algorithm__c,
Active_Configuration__r.B2C_CRM_Sync_AuthToken_Settings__r.Retry_Count__c,
Active_Configuration__r.B2C_CRM_Sync_AuthToken_Settings__r.Persist_B2C_AuthTokens__c
FROM B2C_CRM_Sync_Default_Configuration__mdt
WHERE DeveloperName = 'Production_Configuration'
LIMIT 1
];

// Set the output variable to contain the Account Manager configuration settings to leverage
output.put('AccountManagerUrl', configurationProfile.Active_Configuration__r.B2C_CRM_Sync_AuthToken_Settings__r.Account_Manager_Url__c);
output.put('AccountManagerPort', configurationProfile.Active_Configuration__r.B2C_CRM_Sync_AuthToken_Settings__r.Account_Manager_Port__c);
output.put('AccountManagerSuffix', configurationProfile.Active_Configuration__r.B2C_CRM_Sync_AuthToken_Settings__r.Account_Manager_Token_Url__c);
output.put('ExpirationInMinutes', String.valueOf(configurationProfile.Active_Configuration__r.B2C_CRM_Sync_AuthToken_Settings__r.Expiration_in_Minutes__c));
output.put('JWTSFDCAlgorithm', configurationProfile.Active_Configuration__r.B2C_CRM_Sync_AuthToken_Settings__r.JWT_Algorithm__c);
output.put('JWTSFCCAlgorithm', configurationProfile.Active_Configuration__r.B2C_CRM_Sync_AuthToken_Settings__r.JWT_SFCC_Algorithm__c);
output.put('RetryCount', String.valueOf(configurationProfile.Active_Configuration__r.B2C_CRM_Sync_AuthToken_Settings__r.Retry_Count__c));
output.put('PersistAuthTokens', String.valueOf(configurationProfile.Active_Configuration__r.B2C_CRM_Sync_AuthToken_Settings__r.Persist_B2C_AuthTokens__c));
if (
// Validate that we have CRUD permissions to access this data
B2C_CRM_Sync_Default_Configuration__mdt.SObjectType.getDescribe().isAccessible() &&
Schema.SObjectType.B2C_CRM_Sync_Default_Configuration__mdt.fields.DeveloperName.isAccessible() &&
B2C_CRMSync_Setting__mdt.SObjectType.getDescribe().isAccessible() &&
Schema.SObjectType.B2C_CRMSync_Setting__mdt.fields.Account_Record_Type_Developername__c.isAccessible()
) {
// Get the default configuration profile
configurationProfile = [
SELECT Active_Configuration__r.B2C_CRM_Sync_AuthToken_Settings__r.Account_Manager_Url__c,
Active_Configuration__r.B2C_CRM_Sync_AuthToken_Settings__r.Account_Manager_Port__c,
Active_Configuration__r.B2C_CRM_Sync_AuthToken_Settings__r.Account_Manager_Token_Url__c,
Active_Configuration__r.B2C_CRM_Sync_AuthToken_Settings__r.Expiration_in_Minutes__c,
Active_Configuration__r.B2C_CRM_Sync_AuthToken_Settings__r.JWT_Algorithm__c,
Active_Configuration__r.B2C_CRM_Sync_AuthToken_Settings__r.JWT_SFCC_Algorithm__c,
Active_Configuration__r.B2C_CRM_Sync_AuthToken_Settings__r.Retry_Count__c,
Active_Configuration__r.B2C_CRM_Sync_AuthToken_Settings__r.Persist_B2C_AuthTokens__c
FROM B2C_CRM_Sync_Default_Configuration__mdt
WHERE DeveloperName = 'Production_Configuration'
LIMIT 1
];

// Set the output variable to contain the Account Manager configuration settings to leverage
output.put('AccountManagerUrl', configurationProfile.Active_Configuration__r.B2C_CRM_Sync_AuthToken_Settings__r.Account_Manager_Url__c);
output.put('AccountManagerPort', configurationProfile.Active_Configuration__r.B2C_CRM_Sync_AuthToken_Settings__r.Account_Manager_Port__c);
output.put('AccountManagerSuffix', configurationProfile.Active_Configuration__r.B2C_CRM_Sync_AuthToken_Settings__r.Account_Manager_Token_Url__c);
output.put('ExpirationInMinutes', String.valueOf(configurationProfile.Active_Configuration__r.B2C_CRM_Sync_AuthToken_Settings__r.Expiration_in_Minutes__c));
output.put('JWTSFDCAlgorithm', configurationProfile.Active_Configuration__r.B2C_CRM_Sync_AuthToken_Settings__r.JWT_Algorithm__c);
output.put('JWTSFCCAlgorithm', configurationProfile.Active_Configuration__r.B2C_CRM_Sync_AuthToken_Settings__r.JWT_SFCC_Algorithm__c);
output.put('RetryCount', String.valueOf(configurationProfile.Active_Configuration__r.B2C_CRM_Sync_AuthToken_Settings__r.Retry_Count__c));
output.put('PersistAuthTokens', String.valueOf(configurationProfile.Active_Configuration__r.B2C_CRM_Sync_AuthToken_Settings__r.Persist_B2C_AuthTokens__c));
}

// Return the associated Account Manager configuration settings
return output;
Expand All @@ -57,34 +65,26 @@ public with sharing class B2CConfigurationManager {
* @return {String} Returns the developerName for the B2c Business Account
*/
public static String getAccountRecordTypeDeveloperName() {

// Initialize local variables
B2C_CRM_Sync_Default_Configuration__mdt configurationProfile;
String output;

if (
// Validate that we have CRUD permissions to access this data
B2C_CRM_Sync_Default_Configuration__mdt.SObjectType.getDescribe().isAccessible() &&
Schema.SObjectType.B2C_CRM_Sync_Default_Configuration__mdt.fields.DeveloperName.isAccessible() &&
B2C_CRMSync_Setting__mdt.SObjectType.getDescribe().isAccessible() &&
Schema.SObjectType.B2C_CRMSync_Setting__mdt.fields.Account_Record_Type_Developername__c.isAccessible()
) {

// Get the default configuration profile
configurationProfile = [
B2C_CRM_Sync_Default_Configuration__mdt configurationProfile = [
SELECT Active_Configuration__r.Account_Record_Type_Developername__c
FROM B2C_CRM_Sync_Default_Configuration__mdt
WHERE DeveloperName = 'Production_Configuration'
LIMIT 1
];

// Set the output variable to contain the specified configuration property
output = configurationProfile.Active_Configuration__r.Account_Record_Type_Developername__c;
return configurationProfile.Active_Configuration__r.Account_Record_Type_Developername__c;

}

// Return the configured account / recordType developerName
return output;
return null;

}

Expand All @@ -101,19 +101,19 @@ public with sharing class B2CConfigurationManager {
B2C_CRMSync_Setting__mdt.SObjectType.getDescribe().isAccessible() &&
Schema.SObjectType.B2C_CRMSync_Setting__mdt.fields.PersonAccount_Record_Type_Developername__c.isAccessible()
) {
return null;
}
// Get the default configuration profile
B2C_CRM_Sync_Default_Configuration__mdt configurationProfile = [
SELECT Active_Configuration__r.PersonAccount_Record_Type_Developername__c
FROM B2C_CRM_Sync_Default_Configuration__mdt
WHERE DeveloperName = 'Production_Configuration'
LIMIT 1
];

// Get the default configuration profile
B2C_CRM_Sync_Default_Configuration__mdt configurationProfile = [
SELECT Active_Configuration__r.PersonAccount_Record_Type_Developername__c
FROM B2C_CRM_Sync_Default_Configuration__mdt
WHERE DeveloperName = 'Production_Configuration'
LIMIT 1
];
// Set the output variable to contain the specified configuration property
return configurationProfile.Active_Configuration__r.PersonAccount_Record_Type_Developername__c;
}

// Set the output variable to contain the specified configuration property
return configurationProfile.Active_Configuration__r.PersonAccount_Record_Type_Developername__c;
return null;
}

/**
Expand All @@ -122,34 +122,26 @@ public with sharing class B2CConfigurationManager {
* @return {String} Returns the configured customerModel (Standard or Person).
*/
public static String getDefaultAccountContactModel() {

// Initialize local variables
B2C_CRM_Sync_Default_Configuration__mdt configurationProfile;
String output;

if (
// Validate that we have CRUD permissions to access this data
B2C_CRM_Sync_Default_Configuration__mdt.SObjectType.getDescribe().isAccessible() &&
Schema.SObjectType.B2C_CRM_Sync_Default_Configuration__mdt.fields.DeveloperName.isAccessible() &&
B2C_CRMSync_Setting__mdt.SObjectType.getDescribe().isAccessible() &&
Schema.SObjectType.B2C_CRMSync_Setting__mdt.fields.Account_Contact_Model__c.isAccessible()
) {

// Get the default configuration profile
configurationProfile = [
B2C_CRM_Sync_Default_Configuration__mdt configurationProfile = [
SELECT Active_Configuration__r.Account_Contact_Model__c
FROM B2C_CRM_Sync_Default_Configuration__mdt
WHERE DeveloperName = 'Production_Configuration'
LIMIT 1
];

// Set the output variable to contain the specified configuration property
output = configurationProfile.Active_Configuration__r.Account_Contact_Model__c;
return configurationProfile.Active_Configuration__r.Account_Contact_Model__c;

}

// Return the configured customerModel
return output;
return null;

}

Expand Down
Expand Up @@ -118,7 +118,7 @@ public inherited sharing class B2CIACustomerResolution {
);

//If so, iterate over them and start checking for potential matches
for ( Datacloud.FindDuplicatesResult fdrI : results ) {
for (Datacloud.FindDuplicatesResult fdrI : results) {

System.debug(LoggingLevel.DEBUG, '--> Iterating Over DataCloud results (' + results.size() + ')');

Expand Down
Expand Up @@ -291,16 +291,7 @@ public with sharing class B2CIACustomerResolution_TestHelper {
* @return {RecordType} Represent the recordType retrieved via the SOQL query
*/
public static RecordType getRecordType(String recordTypeDeveloperName) {

// Initialize local variables
RecordType output;

// Retrieve the specified recordType using the developerName that is passed in
output = [ SELECT Id, DeveloperName FROM RecordType WHERE DeveloperName = :recordTypeDeveloperName ];

// Return the query results
return output;

return [ SELECT Id, DeveloperName FROM RecordType WHERE DeveloperName = :recordTypeDeveloperName ];
}

}
Expand Up @@ -260,10 +260,7 @@ public with sharing class B2CProcessContactHelper extends B2CBaseAttributeAssign
) {

// Initialize local variables
B2C_Commerce_ProcessCustomerDetails__e thisPE;

// Default the platform event
thisPE = new B2C_Commerce_ProcessCustomerDetails__e();
B2C_Commerce_ProcessCustomerDetails__e thisPE = new B2C_Commerce_ProcessCustomerDetails__e();

// Seed the platform event with core properties from the contactInput class
thisPE.Api_Url__c = validateContactInput.customerList.Base_API_Url__c;
Expand Down
Expand Up @@ -302,10 +302,8 @@ private class B2CProcessContactHelper_Test {
static void testProcessTrigger() {

// Initialize local Variables
List<Contact> triggerNew;
List<Contact> triggerOld;
Contact newContact;
Contact oldContact;
List<Contact> triggerNew = new List<Contact>();
List<Contact> triggerOld = new List<Contact>();

// Initialize local variables
triggerNew = new List<Contact>();
Expand Down Expand Up @@ -369,8 +367,8 @@ private class B2CProcessContactHelper_Test {
Contact sourceContact = sourceContacts.get(0);

// Clone the test contact and make updates
newContact = sourceContact.clone(true, true);
oldContact = sourceContact.clone(true, true);
Contact newContact = sourceContact.clone(true, true);
Contact oldContact = sourceContact.clone(true, true);

Test.startTest();

Expand Down
Expand Up @@ -210,7 +210,8 @@ private class B2CProcessContact_EvalContactArg_Test {

// Initialize the testContact record
Account testAccount = (Account) TestDataFactory.createSObject('Account', new Map<String,Object>{
'Name' => 'Registered Customer'
'Name' => 'Registered Customer',
'RecordTypeId' => B2CIACustomerResolution_TestHelper.getRecordType(B2CConfigurationManager.getAccountRecordTypeDeveloperName()).Id
});

// Initialize the testContact record with the AccountId
Expand Down

0 comments on commit 60b5971

Please sign in to comment.