Untitled

mail@pastecode.io avatar
unknown
plain_text
3 years ago
14 kB
4
Indexable
Never
/**
 * @description       : 
 * @author            : Thiago Barbosa
 * @group             : 
 * @last modified on  : 12-03-2021
 * @last modified by  : ChangeMeIn@UserSettingsUnder.SFDoc
**/
@IsTest 
public with sharing class CEP_SRV_OrderManagementCreationTst {


    private static Id osiRecordType = CEP_UTL_RecordType.getRecordTypeIdByDeveloperName('Electric', 'OpportunityServiceItem__c');   

    @TestSetup
    static void setup(){
        
        wrts_prcgvr.InstallIntegration.install();
        insert TestDataCustomer.createPhaseManagerSettingFileMetadata();
        insert TestDataCustomer.createPhaseManagerSettingOpportunity();
        insert TestDataCustomer.createPhaseManagerSettingCase();
        insert TestDataCustomer.createPhaseManagerSettingIntegration();
        insert TestDataCustomer.createPhaseManagerSettingIntegrationCase();
        insert TestDataCustomer.createPhase('Creato');
        insert TestDataCustomer.createPhase('Attesa Perfezionamento');

        insert TestDataCustomer.createPhase('START');
        insert TestDataCustomer.createPhase('INVIO');
        wrts_prcgvr__PhaseTransition__c pt = new wrts_prcgvr__PhaseTransition__c(
            wrts_prcgvr__Code__c = 'code',
            wrts_prcgvr__Type__c = 'A',
            wrts_prcgvr__RecordTypeId__c = Schema.SObjectType.IntegrationCase__c.getRecordTypeInfosByDeveloperName().get('CEP_RT_RateChange').getRecordTypeId(),
            wrts_prcgvr__RecordTypeName__c = 'CEP_RT_RateChange',
            wrts_prcgvr__OriginPhase__c = 'START',
            wrts_prcgvr__DestinationPhase__c = 'INVIO',
            wrts_prcgvr__Tags__c = ''
        );
        insert pt;
        
         
        Account account = TestDataCustomer.account().physicalPersonAccount().build();

        insert account;
 
        Contact con = TestDataCustomer.contact().createContact().setAccount(account.Id).build();
        insert con;
        
        Interaction__c interaction = TestDataCustomer.interaction().createInteraction().build();
        insert interaction;
        
        CustomerInteraction__c cusInt = TestDataCustomer.CustomerInteraction().createCustomerInteraction(interaction.Id ,account.Id, con.Id).build();
        insert cusInt;

        ContractAccount__c contractAccount = TestDataFactory.contractAccount().createContractAccount().setAccount(account.Id).build();
        insert contractAccount;    

        Opportunity opty = TestDataCustomer.opportunity().createOpportunity().build();
        opty.Phase__c = 'Confermata';  
        opty.RequestType__c = 'Offerta B2B';     
        opty.SignatureDate__c = Date.today(); 
        opty.PDCType__c = 'Usi Domestici';       
        opty.RecordTypeId = Schema.SObjectType.Opportunity.getRecordTypeInfosByDeveloperName().get('CEP_RT_Business').getRecordTypeId();
        opty.LegalContactFiscalCode__c  = 'NGLRFL86S24E791T';  
        opty.SafeguardDeclaration__c = 'di avere più di 50 dipendenti';
        opty.RethinkingDate__c = Date.today(); 
        insert opty; 

        Asset asset = new Asset();
        asset.Name = 'AssetTest';
        asset.AccountId = account.Id; 
        asset.ContactId = con.Id; 
        asset.Status = 'Attivo';
        asset.DispatchingContractCode__c = 'DP1005'; 
        insert asset; 

        ServicePoint__c servicePoint = TestDataFactory.servicePoint().createServicePoint().build(); 
        servicePoint.Key__c = 'IT002E1231313A';
        servicePoint.CurrentAsset__c = asset.Id; 
        servicePoint.PointAddressNormalized__c = false; 
        insert servicePoint; 


        OpportunityServiceItem__c opportunityServiceItem = TestDataCustomer.opportunityServiceItem().createOpportunityServiceItem().build();
		opportunityServiceItem.Opportunity__c = opty.Id;  
        opportunityServiceItem.RecordTypeId = osiRecordType;
        opportunityServiceItem.Treatment__c = 'Tipologia prezzo Fasce';    
		opportunityServiceItem.ServicePoint__c = servicePoint.Id;
        opportunityServiceItem.Process__c = 'SWITCHING WIN';   
        opportunityServiceItem.Usage__c = 'Domestico';   
        opportunityServiceItem.Segment__c = 'Business'; 
        opportunityServiceItem.PointStreetType__c = 'Viale';  
        opportunityServiceItem.Account__c = account.Id;    
        opportunityServiceItem.RecordTypeId = Schema.SObjectType.OpportunityServiceItem__c.getRecordTypeInfosByDeveloperName().get('Electric').getRecordTypeId();
        opportunityServiceItem.VoltageLevel__c = 'MT Trifase'; 
        opportunityServiceItem.Voltage__c = 220;   
        opportunityServiceItem.PointCity__c = 'ROMA';     
        opportunityServiceItem.PDRType__c = 'PDR nella titolarità di un cliente domestico';
        opportunityServiceItem.RequestedIndustrialSector__c = 'USO DOMESTICO';
        opportunityServiceItem.RequestedContractualPower__c = '5'; 
		insert opportunityServiceItem;    

        Case cs = TestDataCustomer.case().createCase(account.Id).build();
        cs.OpportunityServiceItem__c = opportunityServiceItem.Id;
        cs.Opportunity__c = opty.Id;
        cs.Status = 'In Lavorazione';
        insert cs;

        IntegrationCase__c ic = TestDataCustomer.integrationCase().createIntegrationCase(cs.Id, account.Id).build();    
        ic.RecordTypeId = Schema.SObjectType.IntegrationCase__c.getRecordTypeInfosByDeveloperName().get('CEP_RT_Cancellation').getRecordTypeId();
        insert ic;

        CustomReminder__c customReminder = new CustomReminder__c();
        customReminder.Code__c = 'test123';
        customReminder.Status__c = 'Executed';
        customReminder.IntegrationCase__c = ic.Id; 
        customReminder.OpportunityServiceItem__c = opportunityServiceItem.Id;
		customReminder.RecordId__c = ic.Id; 
        insert customReminder;
    }

    @IsTest
    static void createOrderManagementChainTest(){
    
        Opportunity opp = [SELECT ID ,Channel__c, SubChannel__c FROM Opportunity LIMIT 1];

        OpportunityServiceItem__c osi = [SELECT Id FROM OpportunityServiceItem__c LIMIT 1];
        osi.Process__c = 'Disattivazione';
        osi.Opportunity__c = opp.Id;  
        osi.DeactivationDate__c = Date.today(); 
        update osi; 
        Set<Id> oppIds = new Set<Id>();

        oppIds.add(opp.Id);

        Test.startTest();
        Object result = CEP_SRV_OrderManagementCreation.createOrderManagementChain(oppIds);
        System.assertEquals(null, result, 'Result should be null');
        Test.stopTest();
    }


    @IsTest
    static void createOrderManagementChainNewTest(){
        
        Opportunity opp = [SELECT ID ,Channel__c, SubChannel__c FROM Opportunity LIMIT 1];

        ServicePoint__c  servicePoint = [SELECT Id FROM ServicePoint__c LIMIT 1];
        servicePoint.RecordTypeId = CEP_UTL_RecordType.getRecordTypeIdByDeveloperName('Gas', 'ServicePoint__c'); 
        update servicePoint; 
        IntegrationCase__c intCase = [SELECT Id FROM IntegrationCase__c LIMIT 1];
        intCase.ServicePoint__c = servicePoint.Id; 
        update intCase;
        
        CustomReminder__c customReminder = [SELECT Id, IntegrationCase__r.Commodity__c FROM CustomReminder__c LIMIT 1];
        customReminder.IntegrationCase__c = intCase.Id;
        update customReminder; 
 
        OpportunityServiceItem__c osi = [SELECT Id FROM OpportunityServiceItem__c LIMIT 1];
        osi.Process__c = 'Disattivazione';
        osi.Opportunity__c = opp.Id;  
        osi.DeactivationDate__c = Date.today() +31; 
        update osi;
        Set<Id> oppIds = new Set<Id>();

        oppIds.add(opp.Id);

        Test.startTest();
        Object result = CEP_SRV_OrderManagementCreation.createOrderManagementChain(oppIds);
        System.assertEquals(null, result, 'Result should be null');
        Test.stopTest();
    }



    @IsTest
    static void createOrderManagementCAMBIOPRODOTTOTest(){
        
        Opportunity opp = [SELECT ID ,Channel__c, SubChannel__c FROM Opportunity LIMIT 1];
 
        OpportunityServiceItem__c osi = [SELECT Id FROM OpportunityServiceItem__c LIMIT 1];
        osi.Process__c = 'CAMBIO PRODOTTO'; 
        osi.Opportunity__c = opp.Id;  
        osi.DeactivationDate__c = Date.today() +31; 
        update osi;
        Set<Id> oppIds = new Set<Id>();

        oppIds.add(opp.Id);

        Test.startTest();
        Object result = CEP_SRV_OrderManagementCreation.createOrderManagementChain(oppIds);
        System.assertEquals(null, result, 'Result should be null');
        Test.stopTest();
    }

    @IsTest 
    static void startOrderManagmentTest(){
        Opportunity opp = [SELECT ID ,Channel__c, SubChannel__c FROM Opportunity LIMIT 1];

        Test.startTest();
        Account acc = [Select id from account limit 1];
        OpportunityServiceItem__c osi = [Select id from opportunityServiceItem__c limit 1];
        case c = TestDataCustomer.case().createCase(acc.Id).build();
        ContractAccount__c ca = [Select id from contractaccount__c limit 1];
        c.Status = 'Bozza';
        c.Phase__c = 'BOZZA';
        c.RecordTypeId = Schema.SObjectType.Case.getRecordTypeInfosByDeveloperName().get('Activation_ELE').getRecordTypeId();
        c.OpportunityServiceItem__c = osi.Id; 
        c.Opportunity__c = opp.Id; 
        insert c;
        IntegrationCase__c ic = TestDataCustomer.integrationCase().createIntegrationCase(c.Id, acc.Id).build();
        ic.RecordTypeId = Schema.SObjectType.IntegrationCase__c.getRecordTypeInfosByDeveloperName().get('CEP_RT_ActivationEle').getRecordTypeId();
        ic.Phase__c = 'START';
        ic.ANCSkipped__c = false;
        ic.ContractAccount__c = ca.Id;
        ic.Opportunity__c = opp.Id; 
        insert ic;
        List<IntegrationCase__c> icList = [SELECT Id FROM IntegrationCase__c];
        try{
            CEP_SRV_OrderManagementCreation.startOrderManagment(opp.Id);
        }
        catch(Exception ex){
            System.debug(ex.getMessage());
        }

        System.assertEquals(false, icList.isEmpty());
        Test.stopTest();       
    }
    
    @isTest  
    static void createOrderManagementChainRTRateChangeTest(){

        try{  
        Test.startTest();  
        Account acc = [SELECT Id, (SELECT Id FROM Contacts limit 1) FROM Account Limit 1];
        Contact cont = acc.Contacts[0]; 
        
        Opportunity opp = [SELECT Id FROM Opportunity LIMIT 1];
        opp.ContactDigitalCompletion__c = cont.Id;
        opp.RecordTypeId = Schema.SObjectType.Opportunity.getRecordTypeInfosByDeveloperName().get('CEP_RT_Generic').getRecordTypeId();
        opp.Process__c = 'Cambio Tariffa (Residente/Non Residente)';
        opp.Channel__c = 'Call Center';
        update opp; 

        OpportunityServiceItem__c osi = [SELECT Id FROM OpportunityServiceItem__c LIMIT 1];
        osi.Process__c = 'SWITCHING WIN';  
        osi.RecordTypeId = Schema.SObjectType.OpportunityServiceItem__c.getRecordTypeInfosByDeveloperName().get('Electric').getRecordTypeId();
        osi.Opportunity__c = opp.Id;
        Database.SaveResult resultAssert = Database.update(osi);

     
         
            Object result = CEP_SRV_OrderManagementCreation.createOrderManagementChain(new Set<Id> {opp.Id});
            System.assert(resultAssert.isSuccess(), 'The Opportunity was updated'); 
          
        }catch(Exception ex){
            System.assertEquals(ex.getMessage(), ex.getMessage(), 'The method generate the Exception'); 
        } 
        Test.stopTest();   

    }

    @isTest 
    static void trascodeProcessToRecordTypeTest(){ 
        
        try{
        Test.startTest(); 
        Id trascode = CEP_SRV_OrderManagementCreation.trascodeProcessToRecordType('Storno Cambio Prodotto', 'Case');
        Test.stopTest();  
        System.assert(String.isNotBlank(trascode), 'the trascode is different of null'); 
        }catch(Exception ex){ 
            System.assertEquals(true, ex.getMessage() != null, 'The method generate the error'); 
        }
    }

    @isTest 
    static void trascodeProcessToRecordTypeException(){
        
        try{
        Test.startTest(); 
        Id trascode = CEP_SRV_OrderManagementCreation.trascodeProcessToRecordType('Disattivazione', 'IntegrationCase__c');
        Test.stopTest();  
        System.assert(String.isNotBlank(trascode), 'the trascode is different of null'); 
        }catch(Exception ex){
            System.assertEquals(ex.getMessage(), ex.getMessage(), 'The method generate the Exception of query'); 
        }
    }

    @isTest 
    static void sendToEbdmTest(){

        Opportunity opp = [SELECT Id FROM Opportunity LIMIT 1];
        Test.startTest();
        CEP_SRV_OrderManagementCreation.sendToEbdm(new Set<Id> { opp.Id}); 
        Test.stopTest(); 
        System.assert(opp != null, 'The Opportunity is different of null');
    }

    @isTest 
    static void getIsBloccatoPdcTest(){ 

        Case caseRecord = [SELECT Id FROM Case LIMIT 1];
        Opportunity opp = [SELECT Id, RecordType.Name, RecordType.DeveloperName FROM Opportunity LIMIT 1];
        Test.startTest();
        Boolean result = CEP_SRV_OrderManagementCreation.getIsBloccatoPdc(caseRecord, opp);
        Test.stopTest();    
        System.assertEquals(false, result == true, 'The result is false');
    }
}