高章伟
2023-03-03 d8dc84a3d56df839895f1c417a4d9cbee763d262
force-app/main/default/classes/Opportunity_Shipments_ForecastBatchTest.cls
@@ -2,6 +2,18 @@
private class Opportunity_Shipments_ForecastBatchTest {
   
   static testMethod void test_method_OSF() {
        StaticParameter.EscapeConsumableOrderDetail2Trigger = true;
        StaticParameter.EscapeNFM007Trigger = true;
        StaticParameter.EscapeOpportunityBefUpdTrigger = true;
        StaticParameter.EscapeOpportunityHpDeptUpdTrigger = true;
        StaticParameter.EscapeSyncOpportunityTrigger = true;
        StaticParameter.EscapeSyncProduct2Trigger = true;
        StaticParameter.EscapeAccountTrigger = true;
        ControllerUtil.EscapeNFM001Trigger = true;
        StaticParameter.EscapeNFM001Trigger = true;
        StaticParameter.EscapeNFM001AgencyContractTrigger = true;
        StaticParameter.EscapeNFM001AgencyContractTrigger2 = true;
      List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        if (rectCo.size() == 0) {
            return;
@@ -60,10 +72,164 @@
        oppIds.add(opps[0].Opportunity_No__c);
        Id execBTId = null;
        System.Test.StartTest();
        execBTId = Database.executeBatch(new Opportunity_Shipments_ForecastBatch(oppIds));
        execBTId = Database.executeBatch(new Opportunity_Shipments_ForecastBatch(oppIds),1);
        
        execBTId = Database.executeBatch(new Opportunity_Shipments_ForecastBatch('20190101'));
        execBTId = Database.executeBatch(new Opportunity_Shipments_ForecastBatch());
        // execBTId = Database.executeBatch(new Opportunity_Shipments_ForecastBatch('20190101'),1);
        // execBTId = Database.executeBatch(new Opportunity_Shipments_ForecastBatch(),1);
        System.Test.StopTest();
    }
    static testMethod void test_method_OSF01() {
        StaticParameter.EscapeConsumableOrderDetail2Trigger = true;
        StaticParameter.EscapeNFM007Trigger = true;
        StaticParameter.EscapeOpportunityBefUpdTrigger = true;
        StaticParameter.EscapeOpportunityHpDeptUpdTrigger = true;
        StaticParameter.EscapeSyncOpportunityTrigger = true;
        StaticParameter.EscapeSyncProduct2Trigger = true;
        StaticParameter.EscapeAccountTrigger = true;
        ControllerUtil.EscapeNFM001Trigger = true;
        StaticParameter.EscapeNFM001Trigger = true;
        StaticParameter.EscapeNFM001AgencyContractTrigger = true;
        StaticParameter.EscapeNFM001AgencyContractTrigger2 = true;
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        if (rectCo.size() == 0) {
            return;
        }
        List<RecordType> rectSct = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 呼吸科'];
        if (rectSct.size() == 0) {
            return;
        }
        List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 消化科'];
        if (rectDpt.size() == 0) {
            return;
        }
        // テストデータ
        Account company = new Account();
        company.RecordTypeId = rectCo[0].Id;
        company.Name         = 'NFM206TestCompany';
        upsert company;
        Account section = new Account();
        section.RecordTypeId = rectSct[0].Id;
        section.Name         = '*';
        section.Department_Class_Label__c = '消化科';
        section.ParentId                  = company.Id;
        section.Hospital_Department_Class__c = company.Id;
        upsert section;
        Account depart = new Account();
        depart.RecordTypeId = rectDpt[0].Id;
        depart.Name         = '*';
        depart.Department_Name__c  = 'NFM206TestDepart';
        depart.ParentId            = section.Id;
        depart.Department_Class__c = section.Id;
        depart.Hospital__c         = company.Id;
        upsert depart;
        Date today = Date.today();
        Date lastDate1 = Date.today().addMonths(1);
        Date lastDate2 = Date.today().addMonths(2);
        Date lastDate3 = Date.today().addMonths(3);
        Opportunity opp = new Opportunity();
        opp.AccountId           = depart.Id;
        opp.Department_Class__c = section.Id;
        opp.Hospital__c         = company.Id;
        opp.SAP_Send_OK__c      = false;
        opp.Name                = 'GZ-SP-NFM009_0';
        opp.Trade__c            = '内貿';
        opp.StageName           = '引合';
        opp.CloseDate           = lastDate1;
        opp.Close_Forecasted_Date__c = lastDate1;
        opp.Stock_apply_status__c = '申请中';
        insert opp;
        //List<Opportunity> oopList = [select Id,Opportunity_No__c from Opportunity where Id = opp.Id]
        List<String> oppIds = new List<String>();
        //oppIds.add(oopList[0].);
        List<Opportunity> opps = [select Opportunity_No__c from Opportunity where Close_Forecasted_Date__c >= :Date.today() and Close_Forecasted_Date__c <= :Date.today().addMonths(2)];
        System.assertEquals(1, opps.size());
        oppIds.add(opps[0].Opportunity_No__c);
        Id execBTId = null;
        System.Test.StartTest();
        // execBTId = Database.executeBatch(new Opportunity_Shipments_ForecastBatch(oppIds),1);
        execBTId = Database.executeBatch(new Opportunity_Shipments_ForecastBatch('20190101'),1);
        // execBTId = Database.executeBatch(new Opportunity_Shipments_ForecastBatch(),1);
        System.Test.StopTest();
    }
    static testMethod void test_method_OSF02() {
        StaticParameter.EscapeConsumableOrderDetail2Trigger = true;
        StaticParameter.EscapeNFM007Trigger = true;
        StaticParameter.EscapeOpportunityBefUpdTrigger = true;
        StaticParameter.EscapeOpportunityHpDeptUpdTrigger = true;
        StaticParameter.EscapeSyncOpportunityTrigger = true;
        StaticParameter.EscapeSyncProduct2Trigger = true;
        StaticParameter.EscapeAccountTrigger = true;
        ControllerUtil.EscapeNFM001Trigger = true;
        StaticParameter.EscapeNFM001Trigger = true;
        StaticParameter.EscapeNFM001AgencyContractTrigger = true;
        StaticParameter.EscapeNFM001AgencyContractTrigger2 = true;
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        if (rectCo.size() == 0) {
            return;
        }
        List<RecordType> rectSct = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 呼吸科'];
        if (rectSct.size() == 0) {
            return;
        }
        List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 消化科'];
        if (rectDpt.size() == 0) {
            return;
        }
        // テストデータ
        Account company = new Account();
        company.RecordTypeId = rectCo[0].Id;
        company.Name         = 'NFM206TestCompany';
        upsert company;
        Account section = new Account();
        section.RecordTypeId = rectSct[0].Id;
        section.Name         = '*';
        section.Department_Class_Label__c = '消化科';
        section.ParentId                  = company.Id;
        section.Hospital_Department_Class__c = company.Id;
        upsert section;
        Account depart = new Account();
        depart.RecordTypeId = rectDpt[0].Id;
        depart.Name         = '*';
        depart.Department_Name__c  = 'NFM206TestDepart';
        depart.ParentId            = section.Id;
        depart.Department_Class__c = section.Id;
        depart.Hospital__c         = company.Id;
        upsert depart;
        Date today = Date.today();
        Date lastDate1 = Date.today().addMonths(1);
        Date lastDate2 = Date.today().addMonths(2);
        Date lastDate3 = Date.today().addMonths(3);
        Opportunity opp = new Opportunity();
        opp.AccountId           = depart.Id;
        opp.Department_Class__c = section.Id;
        opp.Hospital__c         = company.Id;
        opp.SAP_Send_OK__c      = false;
        opp.Name                = 'GZ-SP-NFM009_0';
        opp.Trade__c            = '内貿';
        opp.StageName           = '引合';
        opp.CloseDate           = lastDate1;
        opp.Close_Forecasted_Date__c = lastDate1;
        opp.Stock_apply_status__c = '申请中';
        insert opp;
        //List<Opportunity> oopList = [select Id,Opportunity_No__c from Opportunity where Id = opp.Id]
        List<String> oppIds = new List<String>();
        //oppIds.add(oopList[0].);
        List<Opportunity> opps = [select Opportunity_No__c from Opportunity where Close_Forecasted_Date__c >= :Date.today() and Close_Forecasted_Date__c <= :Date.today().addMonths(2)];
        System.assertEquals(1, opps.size());
        oppIds.add(opps[0].Opportunity_No__c);
        Id execBTId = null;
        System.Test.StartTest();
        // execBTId = Database.executeBatch(new Opportunity_Shipments_ForecastBatch(oppIds),1);
        // execBTId = Database.executeBatch(new Opportunity_Shipments_ForecastBatch('20190101'),1);
        execBTId = Database.executeBatch(new Opportunity_Shipments_ForecastBatch(),1);
        System.Test.StopTest();
    }