1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
@isTest
public class exceteOPDHistoryNoRentalApplyBatchTest {
 
    static void setupTestData(){
        RecordType rectOpp = [select id from RecordType where IsActive = true and SobjectType = 'Opportunity' and DeveloperName = 'Opportunity' ];
        List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName IN ('Department_GI', 'Department_BF') order by DeveloperName desc];
        // 病院を作る
        Account hospital = new Account();
        hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id;
        hospital.Name = 'test hospital';
        insert hospital;
        // 戦略科室を得る
        Account[] strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_OTH'];
        // 診療科を作る
        Account dep = new Account();
        dep.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_OTH'].id;
        dep.Name = 'test dep';
        dep.AgentCode_Ext__c = '9999998';
        dep.ParentId = strategicDep[0].Id;
        dep.Department_Class__c = strategicDep[0].Id;
        dep.Hospital__c = hospital.Id;
        dep.Department_Class_Label__c = '123';
        insert dep;
 
        OPDPlan__c oPDPlan0 = new OPDPlan__c();
        oPDPlan0.Status__c = '计划中';
        oPDPlan0.OPDPlan_ImplementDate__c = Date.today().addDays(14);
        oPDPlan0.NoOpp_Reason__c = 'HCP对应';
        oPDPlan0.OPDType__c = '事件';
        insert oPDPlan0;
    }
 
    static testMethod void testMethod1() {
        setupTestData();
        OPDPlan__c temp = [SELECT Id FROM OPDPlan__c LIMIT 1];
        Database.executeBatch(new exceteOPDHistoryNoRentalApplyBatch());
        Database.executeBatch(new exceteOPDHistoryNoRentalApplyBatch('2024-01-12'));
    }
}