@@ -82,4 +82,38 @@ private class LeadTriggerHandlerTest {
8282 Assert .areEqual (' Assistant' , lead .Title , ' Expected Title \' Assistant\' ' );
8383 }
8484 }
85+
86+ /*
87+ * LeadTriggerHandler.handleTitleNormalization update test
88+ */
89+ @isTest
90+ static void testHandleAutoLeadScoring () {
91+ // Prepare the test data
92+ List <Map <String , Object >> params = new List <Map <String , Object >>();
93+ params .add (new Map <String , Object >{' Lead_Score__c' = > 20 , ' LeadSource' = > null }); // 0
94+ params .
add (
new Map <
String ,
Object >{
' LeadSource' = > ' Other' ,
' Email' = > ' [email protected] ' });
// 0 95+ params .
add (
new Map <
String ,
Object >{
' LeadSource' = > ' Web' ,
' Email' = > ' [email protected] ' });
// 3 96+ params .add (new Map <String , Object >{' Phone' = > ' (908)345-1234' , ' Industry' = > ' Government' }); // 5
97+ params .
add (
new Map <
String ,
Object >{
' LeadSource' = > ' Web' ,
' Email' = > ' [email protected] ' ,
' Phone' = > ' (908)345-2345' });
// 8 98+ params .
add (
new Map <
String ,
Object >{
' Lead_Score__c' = > 10 ,
' Email' = > ' [email protected] ' ,
' Industry' = > ' Technology' });
// 10 99+ params .
add (
new Map <
String ,
Object >{
' LeadSource' = > ' Web' ,
' Email' = > ' [email protected] ' ,
' Industry' = > ' Technology' });
// 13 100+ params .add (new Map <String , Object >{' LeadSource' = > ' Web' , ' Phone' = > ' (908)346-1234' , ' Industry' = > ' Technology' }); // 15
101+ params .
add (
new Map <
String ,
Object >{
' LeadSource' = > ' Web' ,
' Email' = > ' [email protected] ' ,
102+ ' Phone' = > ' (908)346-1234' , ' Industry' = > ' Technology' }); // 18
103+
104+ List <Lead > leadsToScore = TestDataFactory .createLeadsByParams (params , false );
105+
106+ // Perform the test
107+ Test .startTest ();
108+ LeadTriggerHandler .handleAutoLeadScoring (leadsToScore );
109+ Test .stopTest ();
110+
111+ // Assert that the Score calculates correctly
112+ List <Integer > scoreVariants = new List <Integer >{0 , 0 , 3 , 5 , 8 , 10 , 13 , 15 , 18 };
113+ for (Integer i = 0 ; i < leadsToScore .size (); i ++ ) {
114+ Assert .isTrue (leadsToScore [i ].Lead_Score__c <= 18 , ' Lead score shouldn\' t be more than 18' );
115+ Assert .areEqual (scoreVariants [i ], leadsToScore [i ].Lead_Score__c , ' Score has not correctly calculated' );
116+ }
117+
118+ }
85119}
0 commit comments