You need to sign in to do that
Don't have an account?
PARISE RAVIKIRAN
pls help System.AssertException: Assertion Failed: Expected: true, Actual: false Class.LeadTriggerUtilityTest.updateDuplicateLeadsForScoreAndOptOutInsTest: line 1596, column 1
@isTest
static void updateDuplicateLeadsForScoreAndOptOutInsTest(){
User elqIntUser = [Select Id from User where username = :Label.Eloqua_Integration_User_Name limit 1];
Test.startTest();
System.runAs(elqIntUser) {
Lead sfdcLead6 = CreateLead('John', 'Lead 3', OptInOptOutScore, 'Docusign', 'United States');
sfdcLead6.Enagement_Score__c = 10;
sfdcLead6.Profile_Score__c = 5;
sfdcLead6.Hard_Opt_In__c = true;
LeadTriggerControl.executeAfterUpdate = true;
Database.DMLOptions dml3 = new Database.DMLOptions();
dml3.DuplicateRuleHeader.AllowSave = true;
Database.SaveResult sr3 = Database.insert(sfdcLead6, dml3);
}
Test.stopTest();
Lead[] leads = GetLeadsByEmail(OptInOptOutScore);
System.assertEquals(3, leads.size(), leads.size());
for (Lead l : leads) {
system.assertEquals(true, l.Hard_Opt_In__c);
system.assertEquals(10, l.Enagement_Score__c);
system.assertEquals(5, l.Profile_Score__c);
}
Contact[] contacts = GetContactsByEmail(OptInOptOutScore);
System.assertEquals(1, contacts.size(), contacts.size());
for (Contact c : contacts) {
System.assertEquals(false, c.Outreach_Opt_Out__c);
System.assertEquals(LeadToOpportunityUtilityCls.CONSENTED, c.Email_Consent_Status__c);
System.assertEquals(true, c.Hard_Opt_In__c);
}
}
static void updateDuplicateLeadsForScoreAndOptOutInsTest(){
User elqIntUser = [Select Id from User where username = :Label.Eloqua_Integration_User_Name limit 1];
Test.startTest();
System.runAs(elqIntUser) {
Lead sfdcLead6 = CreateLead('John', 'Lead 3', OptInOptOutScore, 'Docusign', 'United States');
sfdcLead6.Enagement_Score__c = 10;
sfdcLead6.Profile_Score__c = 5;
sfdcLead6.Hard_Opt_In__c = true;
LeadTriggerControl.executeAfterUpdate = true;
Database.DMLOptions dml3 = new Database.DMLOptions();
dml3.DuplicateRuleHeader.AllowSave = true;
Database.SaveResult sr3 = Database.insert(sfdcLead6, dml3);
}
Test.stopTest();
Lead[] leads = GetLeadsByEmail(OptInOptOutScore);
System.assertEquals(3, leads.size(), leads.size());
for (Lead l : leads) {
system.assertEquals(true, l.Hard_Opt_In__c);
system.assertEquals(10, l.Enagement_Score__c);
system.assertEquals(5, l.Profile_Score__c);
}
Contact[] contacts = GetContactsByEmail(OptInOptOutScore);
System.assertEquals(1, contacts.size(), contacts.size());
for (Contact c : contacts) {
System.assertEquals(false, c.Outreach_Opt_Out__c);
System.assertEquals(LeadToOpportunityUtilityCls.CONSENTED, c.Email_Consent_Status__c);
System.assertEquals(true, c.Hard_Opt_In__c);
}
}
The test is failing on the line "System.assertEquals(3, leads.size(), leads.size());" which is checking that the number of leads returned by the "GetLeadsByEmail" method is 3. The error message "System.AssertException: Assertion Failed: Expected: true, Actual: false" indicates that the actual number of leads returned does not match the expected value of 3.
It looks like the test is creating a lead with the email "OptInOptOutScore", then checking that three leads were returned with that email. It is likely that the lead is not being created as expected or not being returned when queried using the "GetLeadsByEmail" method.
It's likely that the duplicate rule is preventing the lead insertion, you could add rule header to allow duplicate rule or you could check the lead duplication rule setting.
Also, you could check the logic of LeadTriggerControl.executeAfterUpdate and LeadToOpportunityUtilityCls.CONSENTED and make sure that they are working as expected.