高章伟
2023-03-03 d8dc84a3d56df839895f1c417a4d9cbee763d262
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
@isTest
private class EventToEventDetailsScheduleTest {
     @TestSetup
    static void makeData(){
 
        Date toDayTime = Date.today();
        
        Account hospital = new Account();
        hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id;
        hospital.Name = 'hospitalabc';
        hospital.Is_Active__c = '有効';
        hospital.Attribute_Type__c = '卫生部';
        hospital.Speciality_Type__c = '综合医院';
        hospital.Grade__c = '一级';
        hospital.IF_Coverage_Target_HP__c = '1';
        hospital.OCM_Category__c = 'SLTV';
        hospital.Is_Medical__c = '医疗机构';
        hospital.Town__c = '东京';
        Oly_TriggerHandler.bypass('NFM701ControllerHandler');
        Oly_TriggerHandler.bypass('UpdateContractAimAmountHandler');
        insert hospital;
 
        Product2 pro1 = new Product2(Name='name01',IsActive=true,Family='GI',
                Fixture_Model_No__c='n01',Serial_Lot_No__c='S/N tracing',
                Fixture_Model_No_T__c = 'n01',
                Maintenance_Price_Year__c = 999,
                Extend_Gurantee_Start_MD__c = Date.newInstance(toDayTime.year(),3,2),
                Extend_Gurantee_End_MD__c = Date.newInstance(3999,12,31),
                Extend_new_product_gurantee_MD__c = true,
                PartSupplyFinishDate__c  = Date.newInstance(toDayTime.year()+2,3,2),
                ProductCode_Ext__c='pc01',Manual_Entry__c=false,Brand_Name__c='奥林巴斯',
                Category2__c='本体',
                Category3__c='电子镜');
        insert pro1;
 
        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 = System.Label.Account_Asset_FJZ;
        dep.ParentId = strategicDep[0].Id;
        dep.Department_Class__c = strategicDep[0].Id;
        dep.Hospital__c = hospital.Id;
        Oly_TriggerHandler.bypass('NFM701ControllerHandler');
        Oly_TriggerHandler.bypass('UpdateContractAimAmountHandler');
        insert dep;
        Asset assetA1 = new Asset(Asset_Owner__c = 'Olympus');
        assetA1.RecordTypeId = System.Label.Asset_RecordType;
        assetA1.SerialNumber = 'ass01';
        assetA1.Name = 'ass01';
        assetA1.AccountId = dep.Id;
        assetA1.Guarantee_period_for_products__c = toDayTime;
        assetA1.Hospital__c = hospital.Id;
        assetA1.Product2Id = pro1.Id;
        assetA1.Quantity = 1;
        assetA1.IF_Coverage_Target_Asset__c  = '1';
        insert assetA1;
 
    }
 
 
    static testMethod void myUnitTest() {
        // List<Asset> Assets = [SELECT Id,Hospital__c,Product2.ServiceCategory__c,Product2.Maintenance_Price_Year__c 
     //                             FROM Asset WHERE IF_Coverage_Target_Asset__c = '1'];
 
                // This test runs a scheduled job at midnight Sept. 3rd. 2022
        String CRON_EXP = '0 0 0 3 9 ? 2023';
        //System.Test.startTest();
        // Schedule the test job
        String jobId =
            system.schedule('EventToEventDetailsScheduleTest',
                            CRON_EXP,
                            new EventToEventDetailsSchedule());
        // Get the information from the CronTrigger API object
        CronTrigger ct =
            [SELECT Id, CronExpression, TimesTriggered, NextFireTime
             FROM CronTrigger
             WHERE id = :jobId];
        // Verify the expressions are the same
        System.assertEquals(CRON_EXP, ct.CronExpression);
        // Verify the job has not run
        System.assertEquals(0, ct.TimesTriggered);
        // Verify the next time the job will run
        System.assertEquals('2023-09-03 00:00:00',
                            String.valueOf(ct.NextFireTime));
        //System.Test.stopTest();
    }
}