gzw
2022-02-15 168114b11da83c5005cd608c1b23a66311717a0f
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
// TODO EquipmentSetDailyBatchSchedule.test
@isTest
private class RentalApplyDailyBatchTest {
 
    @isTest static void test_method_Three() {
        // システム管理者
        User user_admin = new User(Test_staff__c = true);
        user_admin.LastName = '_サンブリッジ';
        user_admin.FirstName = 'う';
        user_admin.Alias = 'う';
        user_admin.Email = 'olympusTest03@sunbridge.com';
        user_admin.Username = 'olympusTest03@sunbridge.com';
        user_admin.CommunityNickname = 'う';
        user_admin.IsActive = true;
        user_admin.EmailEncodingKey = 'ISO-2022-JP';
        user_admin.TimeZoneSidKey = 'Asia/Tokyo';
        user_admin.LocaleSidKey = 'ja_JP';
        user_admin.LanguageLocaleKey = 'ja';
        user_admin.ProfileId = System.Label.ProfileId_SystemAdmin;
        user_admin.Province__c = '北京';
        user_admin.Dept__c = '医疗华北营业本部';
        user_admin.Use_Start_Date__c = Date.today().addMonths(-6);
        insert user_admin;
 
        System.runAs(user_admin) {
            // 病院を作る
            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;
            // 产品
            Product2 pro1 = new Product2(Name='name01',IsActive=true,Family='GI',Asset_Model_No__c='n01',Serial_Lot_No__c='S/N tracing',ProductCode_Ext__c='pc01',Manual_Entry__c=false);
            Product2 pro2 = new Product2(Name='name02',IsActive=true,Family='GI',Asset_Model_No__c='n02',Serial_Lot_No__c='Lot tracing',ProductCode_Ext__c='pc02',Manual_Entry__c=false);
            Product2 pro3 = new Product2(Name='name03',IsActive=true,Family='GI',Asset_Model_No__c='n03',Serial_Lot_No__c='S/N tracing',ProductCode_Ext__c='pc03',Manual_Entry__c=false);
            insert new Product2[] {pro1, pro2, pro3};
            // 戦略科室を得る
            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;
            insert dep;
 
            //新建备品借出申请-普通
            Rental_Apply__c raObj = new Rental_Apply__c();
            raObj.Name='*';
            raObj.Product_category__c = 'GI';
            raObj.Person_In_Charge__c = UserInfo.getUserId();
            raObj.applyUser__c =  UserInfo.getUserId();
            raObj.Hospital__c = hospital.Id;//医院
            raObj.Strategic_dept__c = strategicDep[0].id;//战略科室
            raObj.Demo_purpose1__c = '其他';
            raObj.demo_purpose2__c = '其他';
            raObj.Demo_purpose_text__c ='测试用的备品借出申请';
            raObj.Request_shipping_day__c = Date.today() + 5;
            raObj.Hope_Lonaer_date_Num__c = 16;
            raObj.Loaner_received_staff__c = '测试用户';
            raObj.Loaner_received_staff_phone__c = '13700008';
            raObj.direct_send__c = '上门自提';
            raObj.Account__c = dep.id;//科室
            raObj.pickup_time__c = Datetime.now()+8;
            raObj.direct_shippment_address__c = '233333的地址';
            raObj.Phone_number__c = '1234567890';
            insert raObj;
            raObj = [Select Salesdept_text_Update_F__c , Owner_Info_text_Update_F__c FROM Rental_Apply__c];
            System.assertEquals(false, raObj.Salesdept_text_Update_F__c);
            System.assertEquals(false, raObj.Owner_Info_text_Update_F__c);
 
            // 修改申请人信息
            user_admin.Dept__c = '医疗华东营业本部';
            user_admin.Province__c = '上海';
            update user_admin;
            //batch前,公式和text不一致
            raObj = [Select Salesdept_text_Update_F__c
                        , Salesdept_text__c
                        , Salesdept__c
                        , Owner_province_text__c
                        , Owner_province__c
                        , Owner_Info_text_Update_F__c
                    FROM Rental_Apply__c];
            System.assertNotEquals(raObj.Salesdept_text__c, raObj.Salesdept__c);
            System.assertEquals(true, raObj.Salesdept_text_Update_F__c);
            System.assertNotEquals(raObj.Owner_province_text__c, raObj.Owner_province__c);
            System.assertEquals(true, raObj.Owner_Info_text_Update_F__c);
 
            Test.startTest();
            RentalApplyDailyBatch bat = new RentalApplyDailyBatch();
            bat.errorList.add('test');
            Database.executeBatch(bat, 20);
 
            bat = new RentalApplyDailyBatch(1);
            bat.errorList.add('test');
            Database.executeBatch(bat, 20);
            Test.stopTest();
 
            // batch后,更新成一致
            raObj = [Select Salesdept_text_Update_F__c
                        , Salesdept_text__c
                        , Salesdept__c
                        , Owner_province_text__c
                        , Owner_province__c
                        , Owner_Info_text_Update_F__c
                    FROM Rental_Apply__c];
            System.assertEquals(raObj.Salesdept_text__c, raObj.Salesdept__c);
            System.assertEquals(false, raObj.Salesdept_text_Update_F__c);
            System.assertEquals(raObj.Owner_province_text__c, raObj.Owner_province__c);
            System.assertEquals(false, raObj.Owner_Info_text_Update_F__c);
 
        }
    }
 
}