高章伟
2022-02-18 8b5f4c6c281cfa548f92de52c8021e37aa81901e
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
@isTest
private class RentalApplyBeforeUpdateTriggerTest {
    private static Id pricebookId = ControllerUtil.getStandardPricebook().Id;
 
    static testMethod void myUnitTest() {
        OlympusCalendar__c oc1 = new OlympusCalendar__c(Date__c = Date.today().addDays(1), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc2 = new OlympusCalendar__c(Date__c = Date.today().addDays(2), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc3 = new OlympusCalendar__c(Date__c = Date.today().addDays(3), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc4 = new OlympusCalendar__c(Date__c = Date.today().addDays(4), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc5 = new OlympusCalendar__c(Date__c = Date.today().addDays(5), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc6 = new OlympusCalendar__c(Date__c = Date.today().addDays(6), ChangeToHoliday__c=true, ChangeToWorkday__c=false);
        OlympusCalendar__c oc7 = new OlympusCalendar__c(Date__c = Date.today().addDays(7), ChangeToHoliday__c=true, ChangeToWorkday__c=false);
        OlympusCalendar__c oc8 = new OlympusCalendar__c(Date__c = Date.today().addDays(8), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc9 = new OlympusCalendar__c(Date__c = Date.today().addDays(9), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc10 = new OlympusCalendar__c(Date__c = Date.today().addDays(10), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc11 = new OlympusCalendar__c(Date__c = Date.today().addDays(11), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc12 = new OlympusCalendar__c(Date__c = Date.today().addDays(12), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
 
        insert new OlympusCalendar__c[] {oc1,oc2,oc3,oc4,oc5,oc6,oc7,oc8,oc9,oc10,oc11,oc12};
 
        Rental_Apply__c ra = new Rental_Apply__c();
        ra.Request_shipping_day__c = Date.today().addDays(3);
        ra.Request_return_day__c= Date.today().addDays(8);
        ra.demo_purpose2__c = '其他';
        insert ra;
 
        Rental_Apply__c result = [select loaner_date__c from Rental_Apply__c where id = :ra.Id];
        //System.assertEquals(3, result.loaner_date__c);
    }
 
    // 测试删除check
    static testMethod void myUnitTest2() {
        Oly_TriggerHandler.bypass('RentalApplyTriggerHandler');
        Rental_Apply__c rentalApply =  new Rental_Apply__c();
        rentalApply.Status__c = FixtureUtil.raStatusMap.get(FixtureUtil.RaStatus.Yi_Chu_Ku_Zhi_Shi.ordinal());
        rentalApply.Request_return_day__c= Date.today().addDays(32);
        insert rentalApply;
        Oly_TriggerHandler.clearAllBypasses();
 
        try {
            delete rentalApply;
        } catch (Exception e) {
 
        }
        Rental_Apply__c[] raList = [select Id from Rental_Apply__c where Id = :rentalApply.Id];
        System.assertEquals(1, raList.size());
    }
 
    // 测试申请分割
    static testMethod void myUnitTest3() {
        Rental_Apply__c ra = new Rental_Apply__c();
        ra.Name = '*';
        ra.Request_shipping_day__c = Date.today().addDays(3);
        ra.Request_return_day__c= Date.today().addDays(8);
        ra.demo_purpose2__c = '其他';
        insert ra;
 
        List<Rental_Apply__c> raList = [select Id, Name from Rental_Apply__c where Id = :ra.Id];
        String n = raList[0].Name;
 
        Rental_Apply__c ra1 = new Rental_Apply__c();
        ra1.Name = n;
        ra1.Request_shipping_day__c = Date.today().addDays(3);
        ra1.Request_return_day__c= Date.today().addDays(8);
        ra1.Old_Rental_Apply__c = ra.Id;
        ra1.demo_purpose2__c = '其他';
        insert ra1;
 
        List<Rental_Apply__c> raList1 = [select Id, Name from Rental_Apply__c where Id = :ra1.Id];
        System.assertEquals(n, raList1[0].Name);
 
        Rental_Apply__c ra2 = new Rental_Apply__c();
        ra2.Name = n;
        ra2.Request_shipping_day__c = Date.today().addDays(3);
        ra2.Request_return_day__c= Date.today().addDays(8);
        ra2.Old_Rental_Apply__c = ra.Id;
        ra2.demo_purpose2__c = '其他';
        insert ra2;
 
        List<Rental_Apply__c> raList2 = [select Id, Name from Rental_Apply__c where Id = :ra2.Id];
        System.assertEquals(n, raList2[0].Name);
    }
 
    // 测试修理申请check
    static testMethod void myUnitTest4() {
        // 病院を作る
        Account hospital = new Account();
        hospital.recordtypeId = [Select Id FROM RecordType WHERE DeveloperName = 'HP'].id;
        hospital.Name = 'test hospital';
        insert hospital;
 
        // 戦略科室を得る
        List<Account> strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_GI'];
 
        // 診療科を作る
        Account dep = new Account();
        dep.recordtypeId = [Select Id FROM RecordType WHERE DeveloperName = 'Department_GI'].id;
        dep.Name = 'test dep';
        dep.ParentId = strategicDep[0].Id;
        dep.Department_Class__c = strategicDep[0].Id;
        dep.Hospital__c = hospital.Id;
        insert dep;
 
        // 製品を作る
        Product2 productA = new Product2( Name='テスト商品');
        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[0].Id;
        asset.Hospital__c = hospital.Id;
        asset.SerialNumber = 'testserial';
        insert asset;
 
        // 修理做成
        Repair__c repair01 = new Repair__c();
        repair01.Account__c = dep.Id;
        repair01.Department_Class__c = strategicDep[0].Id;
        repair01.Hospital__c = hospital.Id;
        repair01.Delivered_Product__c = asset.Id;
        repair01.SERVICE_CONTRACT_JUDEGE_DAY__C = Date.today().addDays(0);  // 维修合同判断日がサービス契約の中間辺りの日付
        insert repair01;
 
        Rental_Apply__c ra = new Rental_Apply__c();
        ra.Name = 'test';
        ra.Request_shipping_day__c = Date.today().addDays(3);
        ra.Request_return_day__c= Date.today().addDays(8);
        ra.Repair__c = repair01.Id;
        ra.demo_purpose2__c = '其他';
        insert ra;
 
        Rental_Apply__c ra1 = new Rental_Apply__c();
        ra1.Name = 'test1';
        ra1.Request_shipping_day__c = Date.today().addDays(3);
        ra1.Request_return_day__c= Date.today().addDays(8);
        ra1.Repair__c = repair01.Id;
        ra1.demo_purpose2__c = '其他';
        try {
            insert ra1;
        } catch (Exception ex) {
            // 同一个型号的修理记录不能重复申请备品
        }
 
        Rental_Apply__c ra2 = new Rental_Apply__c();
        ra2.Name = 'test2';
        ra2.Request_shipping_day__c = Date.today().addDays(3);
        ra2.Request_return_day__c= Date.today().addDays(8);
        ra2.demo_purpose2__c = '其他';
        insert ra2;
 
        ra2.Repair__c = repair01.Id;
        ra2.HP_received_sign_rich__c = 'hhh';
        ra2.HP_received_sign_NG__c = false;
        try {
            update ra2;
        } catch (Exception ex) {
            // 同一个型号的修理记录不能重复申请备品
        }
    }
    // 测试QIS申请check
    static testMethod void myUnitTest5() {
 
        // 病院を作る
        Account hospital = new Account();
        hospital.recordtypeId = [Select Id FROM RecordType WHERE DeveloperName = 'HP'].id;
        hospital.Name = 'test hospital';
        insert hospital;
 
        // 戦略科室を得る
        List<Account> strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_GI'];
 
        // 診療科を作る
        Account dep = new Account();
        dep.recordtypeId = [Select Id FROM RecordType WHERE DeveloperName = 'Department_GI'].id;
        dep.Name = 'test dep';
        dep.ParentId = strategicDep[0].Id;
        dep.Department_Class__c = strategicDep[0].Id;
        dep.Hospital__c = hospital.Id;
        insert dep;
 
        // 製品を作る
        Product2 productA = new Product2( Name='テスト商品');
        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[0].Id;
        asset.Hospital__c = hospital.Id;
        asset.SerialNumber = 'testserial';
        insert asset;
 
        // QIS做成
        QIS_Report__c qis = new QIS_Report__c();
        qis.name = '1';
        qis.RecordTypeID = [Select Id FROM RecordType WHERE DeveloperName = 'RC'].id;
        insert qis;
 
        Rental_Apply__c ra = new Rental_Apply__c();
        ra.Name = 'test';
        ra.Request_shipping_day__c = Date.today().addDays(3);
        ra.Request_return_day__c= Date.today().addDays(8);
        ra.QIS_number__c = qis.Id;
        ra.demo_purpose2__c = '其他';
        insert ra;
 
        Rental_Apply__c ra1 = new Rental_Apply__c();
        ra1.Name = 'test1';
        ra1.Request_shipping_day__c = Date.today().addDays(3);
        ra1.Request_return_day__c= Date.today().addDays(8);
        ra1.QIS_number__c = qis.Id;
        ra1.demo_purpose2__c = '其他';
        try {
            insert ra1;
        } catch (Exception ex) {
            // 同一个QIS记录不能重复申请备品
        }
 
        Rental_Apply__c ra2 = new Rental_Apply__c();
        ra2.Name = 'test2';
        ra2.Request_shipping_day__c = Date.today().addDays(3);
        ra2.Request_return_day__c= Date.today().addDays(8);
        ra2.demo_purpose2__c = '其他';
        ra2.HP_received_sign_rich__c = 'hhh';
        insert ra2;
 
        ra2.QIS_number__c = qis.Id;
        ra2.HP_received_sign_NG__c = true;
        ra2.HP_received_sign_rich__c = 'aaaaa';
        try {
            update ra2;
        } catch (Exception ex) {
            // 同一个QIS记录不能重复申请备品
        }
    }
}