Skip to content

Commit

Permalink
Merge pull request #8 from detonation0/master
Browse files Browse the repository at this point in the history
Fixes and enhancements for March 12, 2018 Release (v18.312)
  • Loading branch information
Kara McIntyre authored Mar 13, 2018
2 parents 21a95e7 + 0986048 commit 5f22c2c
Show file tree
Hide file tree
Showing 12 changed files with 404 additions and 211 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.iml
.idea/
IlluminatedCloud
33 changes: 26 additions & 7 deletions src/classes/INT_InteractionMappingService.cls
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
******************************************/
public class INT_InteractionMappingService {
private Map<String, Set<String>> skipMappingMap = new Map<String, Set<String>>();
private Map<String, List<Interaction_Mapping__c>> intMappingMap = new Map<String, List<Interaction_Mapping__c>>();
public Map<String, List<Interaction_Mapping__c>> intMappingMap = new Map<String, List<Interaction_Mapping__c>>();

public INT_InteractionMappingService() {
for (Interaction_Mapping__c mapping : [
SELECT Skip_Mapping__c, Insert_Null__c, Target_Object_API_Name__c, Interaction_Source_Field_API_Name__c, Target_Field_API_Name__c
SELECT Skip_Mapping__c, Insert_Null__c, Target_Object_API_Name__c, Source_Field_API_Name__c,
Target_Field_API_Name__c, Source_Object_API_Name__c
FROM Interaction_Mapping__c
WHERE Active__c = true
]) {
Expand All @@ -27,10 +28,10 @@ public class INT_InteractionMappingService {
}

/**
* @description Checks to see if field has an excluded source
* @description Checks to see if field has an excluded source
* @param mappingId, the Interaction_Mapping__c record Id to pull the record from the Map.
* @param interactionSource, the value of the Interaction.Interaction_Source__c field.
* @param skipOrPreserveSourcesMap, the Map containing the Skip Mapping
* @param skipOrPreserveSourcesMap, the Map containing the Skip Mapping
* @return a Boolean determining whether or not the field is excluded or overwrite if blank.
*/
private Boolean isSkipOrPreserveSourceField(
Expand All @@ -57,15 +58,33 @@ public class INT_InteractionMappingService {
if (isSkipOrPreserveSourceField(mapping.Id, interaction.Interaction_Source__c, skipMappingMap)) {
continue; // Prevent mapping of field if it's a skip field or a preserve target source
} else if (mapping.Insert_Null__c
|| (interaction.get(mapping.Interaction_Source_Field_API_Name__c) != null
&& interaction.get(mapping.Interaction_Source_Field_API_Name__c) != '')
|| (interaction.get(mapping.Source_Field_API_Name__c) != null
&& interaction.get(mapping.Source_Field_API_Name__c) != '')
) {
theObject.put(mapping.Target_Field_API_Name__c, interaction.get(mapping.Interaction_Source_Field_API_Name__c));
theObject.put(mapping.Target_Field_API_Name__c, interaction.get(mapping.Source_Field_API_Name__c));
}

}
}

return theObject;
}

/**
* @description Applies data from a source Object to the Interaction__c based upon Interaction_Mapping__c records.
* @param theObject, the SObject to pull data from.
* @param interaction, the Interaction__c record to populate.
* @return interaction, the populated Interaction__c record.
*/
public Interaction__c applyDataToInteraction(SObject theObject, Interaction__c interaction) {
if (intMappingMap.containsKey('Interaction__c')) {
for (Interaction_Mapping__c mapping : intMappingMap.get('Interaction__c')) {
if (mapping.Source_Object_API_Name__c == theObject.getSObjectType().getDescribe().getName()) {
interaction.put(mapping.Target_Field_API_Name__c, theObject.get(mapping.Source_Field_API_Name__c));
}
}
}

return interaction;
}
}
179 changes: 103 additions & 76 deletions src/classes/INT_InteractionProcessor.cls

Large diffs are not rendered by default.

96 changes: 73 additions & 23 deletions src/classes/INT_InteractionProcessor_TEST.cls
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@
* Author: Sierra-Cedar
* Description: Unit Tests for INT_InteractionProcessor.cls
******************************************/
@IsTest
@isTest
private class INT_InteractionProcessor_TEST {
@testSetup static void setUpTest() {
@testSetup
static void setUpTest() {
// Create and insert Interaction Mapping Test Data
List<Interaction_Mapping__c> testMappings = INT_TestDataFactory.createTestMappings();
insert testMappings;
}

static testMethod void testInsertDupeLeadsOnlyInImport() {
@isTest
static void testInsertDupeLeadsOnlyInImport() {
// Arrange
List<Interaction__c> interactionsToInsert = new List<Interaction__c>();

Expand Down Expand Up @@ -61,7 +63,8 @@ private class INT_InteractionProcessor_TEST {
'Duplicate pre-processing should have prevented the processing of duplicate records.');
}

static testMethod void testBulkInsertLeadsOnly() {
@isTest
static void testBulkInsertLeadsOnly() {
// Arrange
List<Interaction__c> interactionsToInsert = INT_TestDataFactory.createBulkTestInteractions();

Expand All @@ -75,14 +78,14 @@ private class INT_InteractionProcessor_TEST {
Test.stopTest();

// Assert
List<Lead> leads = [SELECT FirstName, LastName FROM Lead];
List<Contact> contacts = [SELECT Name, AccountId FROM Contact];
System.assert(contacts.size() == 0);
List<Account> accounts = [SELECT Name FROM Account];
System.assert(accounts.size() == 0);
}

static testMethod void testBulkInteractionInsert() {
@isTest
static void testBulkInteractionInsert() {
// Arrange
List<Interaction__c> interactionsToInsert = INT_TestDataFactory.createBulkTestInteractions();

Expand Down Expand Up @@ -130,7 +133,8 @@ private class INT_InteractionProcessor_TEST {
}
}

static testMethod void testPreProcessing() {
@isTest
static void testPreProcessing() {
// Arrange
List<Interaction__c> interactionsToInsert = new List<Interaction__c>();

Expand Down Expand Up @@ -175,9 +179,11 @@ private class INT_InteractionProcessor_TEST {
System.assert(interactions[1].Interaction_Status__c == 'Imported');
}

static testMethod void testOpportunityCreation() {
@isTest
static void testOpportunityCreation() {
// Arrange
Map<String, Schema.RecordTypeInfo> accRTInfo = Account.SObjectType.getDescribe().getRecordTypeInfosByName();
Map<String, Schema.RecordTypeInfo> planRTInfo = Plan__c.SObjectType.getDescribe().getRecordTypeInfosByName();

Account testCollege = new Account(
Name = 'College of Arts & Sciences',
Expand All @@ -191,22 +197,18 @@ private class INT_InteractionProcessor_TEST {
);
insert testUniversity;

Plan__c recruitPlan = new Plan__c(
Name = 'BA - English',
Type__c = 'Recruitment',
Department__c = testCollege.Id,
Career__c = 'Undergraduate',
Active__c = true
);
insert recruitPlan;

Plan__c acadPlan = new Plan__c(
Name = 'Business Administration BA',
Type__c = 'Academic',
Department__c = testCollege.Id,
Career__c = 'Undergraduate',
Active__c = true
);

if (planRTInfo != null && planRTInfo.containsKey('Academic Plan')) {
acadPlan.put('RecordTypeId', planRTInfo.get('Academic Plan').getRecordTypeId());
}

insert acadPlan;

hed__Term__c testFallTerm = new hed__Term__c(
Expand Down Expand Up @@ -261,7 +263,6 @@ private class INT_InteractionProcessor_TEST {
FROM Contact
WHERE Id = :assertInteraction.Contact__c
];
System.assertEquals(assertInteraction.Contact_Title__c, assertContact.Title, 'Title should have been copied over to Contact.');
System.assertEquals(assertInteraction.Birthdate__c, assertContact.Birthdate, 'Birthdate should have been copied over to Contact.');
System.assert(assertContact.hed__Affl_Accounts__r.size() == 1, 'Affiliation should have been created.');
System.assertEquals(assertContact.hed__Affl_Accounts__r[0].hed__Account__c, testUniversity.Id, 'Affiliation Account should have been mapped to the testUniversity.');
Expand All @@ -273,7 +274,8 @@ private class INT_InteractionProcessor_TEST {
System.assertEquals(assertInteraction.Career__c, assertOppty.Career__c, 'Career__c should have been copied over to Opportunity.');
}

static testMethod void testSkipMappingSources() {
@isTest
static void testSkipMappingSources() {
// Arrange
List<Interaction__c> interactionsToInsert = new List<Interaction__c>();

Expand Down Expand Up @@ -303,7 +305,8 @@ private class INT_InteractionProcessor_TEST {
System.assert(accountMap.size() == 1, '1 Account Expected');
}

static testMethod void testCampaignMemberCreation() {
@isTest
static void testCampaignMemberCreation() {
// Arrange
List<Campaign> testCampaigns = new List<Campaign>();

Expand All @@ -330,8 +333,6 @@ private class INT_InteractionProcessor_TEST {
Test.stopTest();

// Assert
List<Interaction__c> interactions = [SELECT First_Name__c, Last_Name__c, Email__c, Gender__c FROM Interaction__c];

List<Lead> assertLeads = [SELECT FirstName, LastName FROM Lead];
System.assert(assertLeads.size() == 0, 'Lead count expected to be at 0. Once converted, the Leads should be deleted');

Expand All @@ -357,4 +358,53 @@ private class INT_InteractionProcessor_TEST {
System.assertEquals(testAddlCampaign.Id, campaignMemberMap.get(testAddlCampaign.Id).CampaignId, 'CampaignMember should have been created for test Campaign.');
System.assertEquals(assertContacts[0].Id, campaignMemberMap.get(testAddlCampaign.Id).ContactId, 'Contact Id should match Contact created.');
}
}

@isTest
static void testCMCreationWithExistingLeadAndCM() {
// Arrange
Lead testLead = new Lead(
FirstName = 'Tony',
LastName = 'Stark',
Email = '[email protected]',
Company = 'Stark, Tony'
);
insert testLead;

Campaign testCampaign = new Campaign(
Name = 'Test Campaign'
);
insert testCampaign;

Campaign testCampaign2 = new Campaign(
Name = 'Test Campaign 2'
);
insert testCampaign2;

CampaignMember testCM = new CampaignMember(
LeadId = testLead.Id,
CampaignId = testCampaign.Id,
Status = 'Added to Campaign'
);
insert testCM;

Interaction__c testInteraction = new Interaction__c(
First_Name__c = 'Tony',
Last_Name__c = 'Stark',
Email__c = '[email protected]',
Campaign__c = testCampaign2.Id,
Campaign_Member_Status__c = 'Added to Campaign'
);

// Act
Test.startTest();
insert testInteraction;
Test.stopTest();

// Assert
Interaction__c assertInteraction = [SELECT Interaction_Status__c FROM Interaction__c WHERE Id = :testInteraction.Id];
System.assertEquals('Imported', assertInteraction.Interaction_Status__c, 'Interaction should have successfully imported.');

List<CampaignMember> assertCampaignMembers = [SELECT Contact.FirstName, Campaign.Name, Status, LeadId, ContactId FROM CampaignMember];
System.assertEquals(2, assertCampaignMembers.size(), '2 Campaign Members should have been created for the Lead/Interaction.');
}
}
Loading

0 comments on commit 5f22c2c

Please sign in to comment.