Test class in Salesforce

0

I am doing a method in a class and also its corresponding test, the thing is that testing it manually in the environment fulfills the functionality perfectly but in the test it does not. I force the one who enters one of my ifs but in the test he does not listen to me.

Here I leave the original method :

private static void checkSupplyDate(Opportunity opp, Map<Id, List<Errors>>errorsMap) {
    List<cscfga__Product_Configuration__c> productConfigs = opportunityProductConfigsMap.get(opp.Id);
    Map<String, Integer> scenarioOffsetDaysMap= new Map<String, Integer>();

    if ((opp.Type == EL_CST.OPPORTUNITY_TYPE_JOIN || opp.Type == null) && productConfigs != null && !productConfigs.isEmpty()) {
        Date actualDate = Date.today();
        if (opp.EL_Closed_Won_Date__c != null) {
            actualDate = opp.EL_Closed_Won_Date__c;
        }
        List<EL_Supply_Date_Validation_Offset__c> supplyOffsetList = [Select id, Name, EL_Supply_Offset_Days__c, EL_Supply_Scenario__c, EL_Target_Sales_Sub_Segment__c from EL_Supply_Date_Validation_Offset__c];

        if(!supplyOffsetList.isEmpty()) {
            for(EL_Supply_Date_Validation_Offset__c sdvo: supplyOffsetList){
                scenarioOffsetDaysMap.put(sdvo.EL_Supply_Scenario__c + sdvo.EL_Target_Sales_Sub_Segment__c, Integer.valueOf(sdvo.EL_Supply_Offset_Days__c));
            }

            for (cscfga__Product_Configuration__c pc : productConfigs) {
                        System.debug('Preferred Start Date Revisar Debug ' + pc.EL_Preferred_Start_of_Supply_Date__c);
                        if (pc.EL_Scenario__c == EL_CST.SVC_SCENARIO_SUPPLIER_SWITCH
                                && ((opp.EL_Target_Sales_Sub_Segment__c == EL_CST.ACCOUNT_SERVICE_SUB_SEGMENT_SME && (actualDate.addDays(scenarioOffsetDaysMap.get(pc.EL_Scenario__c + opp.EL_Target_Sales_Sub_Segment__c))) > pc.EL_Preferred_Start_of_Supply_Date__c)
                                        || (opp.EL_Target_Sales_Sub_Segment__c == EL_CST.ACCOUNT_SERVICE_SUB_SEGMENT_SOHO && (actualDate.addDays(scenarioOffsetDaysMap.get(pc.EL_Scenario__c + opp.EL_Target_Sales_Sub_Segment__c))) > pc.EL_Preferred_Start_of_Supply_Date__c)
                                            || (opp.EL_Target_Sales_Sub_Segment__c == EL_CST.ACCOUNT_SERVICE_SUB_SEGMENT_RES && (actualDate.addDays(scenarioOffsetDaysMap.get(pc.EL_Scenario__c + opp.EL_Target_Sales_Sub_Segment__c))) > pc.EL_Preferred_Start_of_Supply_Date__c)))
                        {
                            addValidationError(errorsMap, opp.Id, Errors.CHECKSUPPLYDATE);
                        }

                        if (pc.EL_Scenario__c == EL_CST.SVC_SCENARIO_SWITCH_ON_DROP
                                && ((opp.EL_Target_Sales_Sub_Segment__c == EL_CST.ACCOUNT_SERVICE_SUB_SEGMENT_SME && (actualDate.addDays(scenarioOffsetDaysMap.get(pc.EL_Scenario__c + opp.EL_Target_Sales_Sub_Segment__c))) > pc.EL_Preferred_Start_of_Supply_Date__c)
                                        || (opp.EL_Target_Sales_Sub_Segment__c == EL_CST.ACCOUNT_SERVICE_SUB_SEGMENT_RES && (actualDate.addDays(scenarioOffsetDaysMap.get(pc.EL_Scenario__c + opp.EL_Target_Sales_Sub_Segment__c))) > pc.EL_Preferred_Start_of_Supply_Date__c)
                                            || (opp.EL_Target_Sales_Sub_Segment__c == EL_CST.ACCOUNT_SERVICE_SUB_SEGMENT_SOHO && (actualDate.addDays(scenarioOffsetDaysMap.get(pc.EL_Scenario__c + opp.EL_Target_Sales_Sub_Segment__c))) > pc.EL_Preferred_Start_of_Supply_Date__c)))
                        {
                           addValidationError(errorsMap, opp.Id, Errors.CHECKSUPPLYDATE);

                        }

                       if (pc.EL_Scenario__c == EL_CST.SVC_SCENARIO_SWITCH_ON_EOC
                                && ((opp.EL_Target_Sales_Sub_Segment__c == EL_CST.ACCOUNT_SERVICE_SUB_SEGMENT_SME && (actualDate.addDays(scenarioOffsetDaysMap.get(pc.EL_Scenario__c + opp.EL_Target_Sales_Sub_Segment__c))) > pc.EL_Preferred_Start_of_Supply_Date__c)
                                        || (opp.EL_Target_Sales_Sub_Segment__c == EL_CST.ACCOUNT_SERVICE_SUB_SEGMENT_RES && (actualDate.addDays(scenarioOffsetDaysMap.get(pc.EL_Scenario__c + opp.EL_Target_Sales_Sub_Segment__c))) > pc.EL_Preferred_Start_of_Supply_Date__c)
                                            || (opp.EL_Target_Sales_Sub_Segment__c == EL_CST.ACCOUNT_SERVICE_SUB_SEGMENT_SOHO && (actualDate.addDays(scenarioOffsetDaysMap.get(pc.EL_Scenario__c + opp.EL_Target_Sales_Sub_Segment__c))) > pc.EL_Preferred_Start_of_Supply_Date__c)))
                        {   
                          addValidationError(errorsMap, opp.Id, Errors.CHECKSUPPLYDATE);
                        }
            }
        }
    }
}

The Test :

public static testmethod void testClosedWon_CheckSuplyDateNegative() {
    generateTestData(false);
    //add invalid supply date
    productConfig.EL_Preferred_Start_of_Supply_Date__c = Date.today().addDays(1);
    productConfig.EL_Scenario__c = EL_CST.SVC_SCENARIO_SUPPLIER_SWITCH;
    update productConfig;
    System.debug('Supply Date : ' + productConfig.EL_Preferred_Start_of_Supply_Date__c);
    productBasket.csordtelcoa__Synchronised_with_Opportunity__c = true;
    update productBasket;
    Test.startTest();
    opp.StageName = EL_CST.OPPORTUNITY_STAGE_CLOSEDWON;
    opp.Type = EL_CST.OPPORTUNITY_TYPE_JOIN;
    opp.EL_Target_Sales_Sub_Segment__c = EL_CST.ACCOUNT_SERVICE_SUB_SEGMENT_SME;
    update opp;
    //STOP TEST
    Test.stopTest();
    //Assert results
    opp = [SELECT StageName, EL_Technical_Validation_Comment__c FROM Opportunity WHERE ID = :opp.ID Limit 1];
    System.AssertEquals(EL_CST.OPPORTUNITY_STAGE_TECHNICAL_VALIDATION, opp.StageName);
    System.AssertEquals(System.Label.EL_Opportunity_Closing_errMsg_Supply_Date_Check, opp.EL_Technical_Validation_Comment__c);
}
  

Error: System.AssertException: Assertion Failed: Expected: Technical validation, Current: Closed / Won

Can you think it could be?

    
asked by Quavius 12.05.2018 в 12:54
source

0 answers