liuyn
2024-03-11 a87f1c3df03078814ee97ad0c8ac200a232419e9
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
@Istest
public with sharing class CBF2batchTest {
    private static Id pricebookId = ControllerUtil.getStandardPricebook().Id;
    
    static Asset createAsset( Account hospital, Account strategicDep, Account dep) {
        // 製品を作る
        Product2 productA = new Product2( Name = 'テスト商品',Asset_Model_No__c = 'BF-1T260');
        insert productA;
 
        // 価格表エントリを作成する
        PricebookEntry entry = new PricebookEntry( Pricebook2Id = pricebookId, Product2Id = productA.Id);
        entry.UnitPrice = 0;
        entry.IsActive = true;
        entry.UseStandardPrice = false;
        entry.CurrencyIsoCode = 'CNY';
        entry.Product2Id = productA.Id;
        insert entry;
 
        // 納入機器を作成する
        Asset asset = new Asset();
        asset.Name = 'テスト機器';
        asset.AccountId = dep.Id;
        asset.Department_Class__c = strategicDep.Id;
        asset.Hospital__c = hospital.Id;
        asset.SerialNumber = 'testserial';
        asset.Quantity = 3;
        asset.Extend_Gurantee_DateTo_Text__c =Date.today().addDays(30);
        asset.IS_Extend_Gurantee_Txt__c =true;
        asset.Order_No__c = 'BJ_2020';
        insert asset;
 
        return asset;
    }
    @testSetup
    private static void setupTestData(){
        //  ControllerUtil.EscapeNFM001Trigger = true;
 
        // 病院を作る
        Profile p = [select Id from Profile where id =:System.Label.ProfileId_SystemAdminGPI];
        // ユーザー作成
        User hpOwner = new User(Test_staff__c = true, LastName = 'hp', FirstName = 'owner', Alias = 'hp', CommunityNickname = 'hpOwner', Email = 'olympus_hpowner@sunbridge.com', Username = 'olympus_hpowner@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id);
        insert hpOwner;
        // 取引先作成
        List<RecordType> rectHp = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        if (rectHp.size() == 0) {
            return;
        }
        List<RecordType> rectDp = [select Id, Name from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 呼吸科' order by Name desc];
        if (rectDp.size() == 0) {
            return;
        }
 
        List<RecordType> rectDpt = [select Id, Name from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 呼吸科' order by Name desc];
        if (rectDpt.size() == 0) {
            return; 
        }
        Account hp1 = new Account(RecordTypeId = rectHp[0].Id,Is_Active__c = '有効' ,Name = 'testHp1', OCM_Category__c = 'H0', OwnerId = hpOwner.Id);
        insert hp1;
 
        Account dp1 = new Account(RecordTypeId = rectDp[0].Id, Is_Active__c = '有効' , Department_Class_Label__c = '呼吸科',
            ParentId  = hp1.id, Name = 'testdp1', OCM_Category__c = 'H0', OwnerId = hpOwner.Id);
        insert dp1;
 
        List<Account> dc1s = [Select Id, Name, Department_Class_Label__c from Account where Parent.Id = :hp1.Id and Department_Class_Label__c  = '呼吸科' order by Department_Class_Label__c];
        
        Account depart1 = new Account();
        depart1.RecordTypeId = rectDpt[0].Id;
        depart1.Name         = 'hospitalName';
        depart1.Department_Name__c  = '診療科1';
        depart1.ParentId            = dc1s[0].Id;
        depart1.Department_Class__c = dc1s[0].Id;
        depart1.Hospital__c         = hp1.Id;
        depart1.Is_Active__c        = '有効';
        insert depart1;
        // Account dep = createDep( depart1, dc1s[0]);
         // 納入機器を作る
         Asset asset = createAsset( hp1, dc1s[0], depart1);
        String BUid = System.Label.interfaceUserID;
        User thisUser = [select Id from User where Id = '00510000000gmxH'];
        System.runAs ( thisUser ){
        //  NFM603Controller.isRunning = false;
        // 修理
         Repair__c re = new Repair__c();
         re.SAPRepairNo__c = '000010168255';
         re.Account__c = depart1.Id;
         re.Department_Class__c = dc1s[0].Id;
         re.Hospital__c = hp1.Id;
         re.Cumulative_Uses__c = 1811;
         re.Cumulative_Times__c = 38011;
         re.AwaitToSendAWS__c = true;
         re.DeliveryLogisticsMode__c = '快递';
         re.engineerSendDate__c = Date.today(); //修理品寄送日
         re.Delivered_Product__c = asset.Id;
         re.Failure_Occurrence_Date__c  = Date.today(); //1.故障发生日
         re.AWS_Data_Id__c = 'sssssswqsss';
         re.Repair_Inspection_Date__c = Date.today();
         insert re;
 
         Repair__c re2 = new Repair__c();
         re2.SAPRepairNo__c = '000010168254';
         re2.Account__c = depart1.Id;
         re2.Department_Class__c = dc1s[0].Id;
         re2.Hospital__c = hp1.Id;
         re2.Cumulative_Uses__c = 0;
         re2.Cumulative_Times__c = 38011;
         re2.AwaitToSendAWS__c = true;
         re2.AWS_Data_Id__c = 'sssssswsss';
         re2.DeliveryLogisticsMode__c = '快递';
         re2.engineerSendDate__c = Date.today(); //修理品寄送日
         re2.Delivered_Product__c = asset.Id;
         re2.Failure_Occurrence_Date__c  = Date.today(); //1.故障发生日
         re2.Repair_Inspection_Date__c = Date.today();
         insert re2;
        }
    }
    @isTest
    private static void testMethod1() {
        User thisUser = [select Id from User where Id = '00510000000gmxH'];
        System.runAs ( thisUser ){
            Account mc = [select id from Account where Is_Active__c = '有効' limit 1];
            // System.Test.startTest();
            Database.executeBatch(new CBF2batch(mc.Id,null),1);
            Database.executeBatch(new CBF2batch(),1);
            Database.executeBatch(new CBF2batch(mc.Id,'xxss'),1);
            CBF2batch.calculateDaysBetween(Date.today(),Date.today().addDays(10));
            // System.Test.stopTest();
        }
    }
}