GWY
2022-05-21 a3460549533111815e7f73d6cef601a58031525d
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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
@isTest
private class AttachmentTriggerTest {
    static void setupTestData() {
        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);
        OlympusCalendar__c oc13 = new OlympusCalendar__c(Date__c = Date.today().addDays(-1), ChangeToHoliday__c=true, ChangeToWorkday__c=false);
        OlympusCalendar__c oc14 = new OlympusCalendar__c(Date__c = Date.today().addDays(-2), ChangeToHoliday__c=true, ChangeToWorkday__c=false);
        OlympusCalendar__c oc15 = new OlympusCalendar__c(Date__c = Date.today().addDays(-3), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc16 = new OlympusCalendar__c(Date__c = Date.today().addDays(-4), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc17 = new OlympusCalendar__c(Date__c = Date.today().addDays(-5), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
 
        insert new OlympusCalendar__c[] {oc1,oc2,oc3,oc4,oc5,oc6,oc7,oc8,oc9,oc10,oc11,oc12,oc13,oc14,oc15,oc16,oc17};
    }
    static testMethod void myTest1() {
        List<RecordType> rectIE = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Customer IE'];
        Account accIE = new Account(
            Name = '*',
            RecordTypeId = rectIE[0].Id,
            OwnerId = UserInfo.getUserId(),
            DivisionName__c='Customer IE',
            FacilityName__c='abc',
            PostCode__c='000000'
        );
        insert accIE; 
        Contact con = new Contact();
        con.LastName = 'test';
        con.AccountId = accIE.Id;
        con.MobilePhone = 'MobilePhoneD__c';
        con.OtherPhone = 'OtherPhoneD__c';
        con.Fax = 'FaxD__c';
        con.Email = 'EmailD__c@test.com';
        con.Phone = 'PhoneD__c';
        con.Title = 'TitleD__c';
        con.Address1__c = 'Address1D__c';
        con.Address2__c = 'Address2D__c';
        con.Address3__c = 'Address3D__c';
        con.Postcode__c = '100111';
        con.ContactStatus__c = 'ContactStatusD__c';
        con.CancelReason__c = 'CancelReasonD__c';
        con.StatusD__c = 'Pass';
        insert con;
        PriceBook2 pricebook =new PriceBook2(
            Name = 'IE'
        );
        insert pricebook;
         
        List<RecordType> rectOpp = [select id from RecordType where IsActive = true and SobjectType = 'Opportunity'];
        // 有预定下单日
        Opportunity opp = new Opportunity(
            Name = 'test opp',
            AccountId = accIE.Id,
            RecordTypeId = rectOpp[0].Id,
            OwnerId = UserInfo.getUserId(),
            StageName = 'Phase3',
            CurrencyIsoCode = 'CNY',
            ProductSegment__c = 'IE',
            CloseDate = Date.today(),
            NewInquiryDate__c = Date.today().addDays(-2),
            ExpectedOrderDate__c = Date.today().addDays(2),
            SalesChannel__c = 'direct'
        );
        insert opp;
        OpportunityContactRole role = new OpportunityContactRole(
            Role  = 'End user',
            IsPrimary = true,
            OpportunityId = opp.Id,
            ContactId = con.Id
            );
        insert role;
        Order odr = new Order(
            Name = '',
            Status = 'Draft',
            AccountId = accIE.Id,
            ApproveStatus__c = 'Draft',
            OpportunityId = opp.Id,
            EffectiveDate = Date.today(),
            EndUser__c = con.Id
        );
        insert odr;
 
        Attachment att = new Attachment(
            Name = 'ORDER-123456.pdf',
            parentId = odr.Id,
            Body = EncodingUtil.base64Decode('test')
        );
        insert att;
 
        Attachment att2 = new Attachment(
            Name = 'not-ORDER-123456.pdf',
            parentId = odr.Id,
            Body = EncodingUtil.base64Decode('test')
        );
        insert att2;
 
        delete att;
    }
 
     static testMethod void myTest2() {
        setupTestData();
        // Implement test code
        List<RecordType> rectLo = [select Id from RecordType where IsActive = true and SobjectType = 'loaner_application__c' and Name = 'IE'];
 
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Customer IE'];
        
        // 新建备品借出申请
        loaner_application__c loaner = new loaner_application__c();
        loaner.Name = 'TEST';
        loaner.RecordTypeId = rectLo[0].id;
        loaner.EC_CODE_1__C = 'DV2-CAMELEONS-CUBE';
        loaner.DEMO_PURPOSE__C = '演示';
        loaner.Request_shipping_Date__c = Date.today();
        loaner.Request_return_Date__c = Date.today();
        loaner.Status__c = '已出库指示';
        loaner.Return_Track_Company__c = '物流公司';
        //loaner.Return_Trake_Staff__c = '返品人';
        insert loaner;
        Attachment att = new Attachment(
            Name = '借用协议-123456.pdf',
            parentId = loaner.Id,
            Body = EncodingUtil.base64Decode('test')
        );
        insert att;
        Attachment att2 = new Attachment(
            Name = '装机确认-123456.pdf',
            parentId = loaner.Id,
            Body = EncodingUtil.base64Decode('test')
        );
        insert att2;
 
        Attachment att3 = new Attachment(
            Name = '收货确认-123456.pdf',
            parentId = loaner.Id,
            Body = EncodingUtil.base64Decode('test')
        );
        insert att3;
        
        try{
        Attachment att4 = new Attachment(
            Name = '借用协议-123456.pdf',
            parentId = loaner.Id,
            Body = EncodingUtil.base64Decode('test')
        );
        insert att4;
        }catch(Exception ex){
            try{
                Attachment att21 = new Attachment(
                    Name = '装机确认-123456.pdf',
                    parentId = loaner.Id,
                    Body = EncodingUtil.base64Decode('test')
                );
                insert att21;
            }catch(Exception ex1){
                try{
                    Attachment att31 = new Attachment(
                        Name = '收货确认-123456.pdf',
                        parentId = loaner.Id,
                        Body = EncodingUtil.base64Decode('test')
                    );
                    insert att31;
                }catch(Exception ex2){
                    return;
                }
            } 
        } 
     }
 
 
      static testMethod void myTest3() {
        setupTestData();
        // Implement test code
        List<RecordType> rectLo = [select Id from RecordType where IsActive = true and SobjectType = 'loaner_application__c' and Name = 'IE'];
 
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Customer IE'];
        
        // 新建备品借出申请
        loaner_application__c loaner = new loaner_application__c();
        loaner.Name = 'TEST';
        loaner.RecordTypeId = rectLo[0].id;
        loaner.EC_CODE_1__C = 'DV2-CAMELEONS-CUBE';
        loaner.DEMO_PURPOSE__C = '演示';
        loaner.Request_shipping_Date__c = Date.today();
        loaner.Request_return_Date__c = Date.today();
        loaner.Status__c = '已出库指示';
        loaner.Return_Track_Company__c = '物流公司';
        //loaner.Return_Trake_Staff__c = '返品人';
        insert loaner;
        Attachment att = new Attachment(
            Name = '借用协议-123456.pdf',
            parentId = loaner.Id,
            Body = EncodingUtil.base64Decode('test')
        );
        insert att;
        Attachment att2 = new Attachment(
            Name = '装机确认-123456.pdf',
            parentId = loaner.Id,
            Body = EncodingUtil.base64Decode('test')
        );
        insert att2;
 
        Attachment att3 = new Attachment(
            Name = '收货确认-123456.pdf',
            parentId = loaner.Id,
            Body = EncodingUtil.base64Decode('test')
        );
        insert att3;
 
        delete att;
        delete att2;
        delete att3;
    }
     static testMethod void myTest4() {
        setupTestData();
        // Implement test code
        List<RecordType> rectLo = [select Id from RecordType where IsActive = true and SobjectType = 'loaner_application__c' and Name = 'IE'];
 
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Customer IE'];
        
        // 新建备品借出申请
        loaner_application__c loaner = new loaner_application__c();
        loaner.Name = 'TEST';
        loaner.RecordTypeId = rectLo[0].id;
        loaner.EC_CODE_1__C = 'DV2-CAMELEONS-CUBE';
        loaner.DEMO_PURPOSE__C = '演示';
        loaner.Request_shipping_Date__c = Date.today();
        loaner.Request_return_Date__c = Date.today();
        loaner.Status__c = '已出库指示';
        loaner.Return_Track_Company__c = '物流公司';
        //loaner.Return_Trake_Staff__c = '返品人';
        loaner.HP_Received_Sign_Date__c  = Date.today();
        loaner.Bollow_Date__c = Date.today();
        insert loaner;
        Attachment att = new Attachment(
            Name = '借用协议-123456.pdf',
            parentId = loaner.Id,
            Body = EncodingUtil.base64Decode('test')
        );
        insert att;
        Attachment att2 = new Attachment(
            Name = '装机确认-123456.pdf',
            parentId = loaner.Id,
            Body = EncodingUtil.base64Decode('test')
        );
        insert att2;
        try{
            delete att;
        }catch(Exception ex){
            try{
                delete att2;
            }catch(Exception ex1){
                return;
            } 
        }
    }
    // 业务活动 附件上传
    static testMethod void myTest5() {
 
        TS_Repair__c tsr = new TS_Repair__c();
        tsr.TSReportDate__c = Date.today();
        insert tsr; 
 
        User_FaultInfo__c uf1 = new User_FaultInfo__c();
        insert uf1;
        FailureAsset__c fa1 = new FailureAsset__c();
        fa1.model__c = 'test1';
        fa1.FAUserFaultInfo__c = uf1.Id;
        insert fa1;
        Attachment att3 = new Attachment(
            Name = 'not-ORDER-123456.pdf',
            parentId = uf1.Id,
            Body = EncodingUtil.base64Decode('test')
        );
        insert att3;
        
        BusinessActivity__c  ba1 = new BusinessActivity__c();
        ba1.BusinessATS__c = tsr.Id;
        ba1.User_FaultInfo__c = uf1.Id;
        insert ba1;
 
        Attachment att = new Attachment(
            Name = 'ORDER-123456.pdf',
            parentId = ba1.Id,
            Body = EncodingUtil.base64Decode('test')
        );
        insert att;
 
        Attachment att2 = new Attachment(
            Name = 'not-ORDER-123456.pdf',
            parentId = ba1.Id,
            Body = EncodingUtil.base64Decode('test')
        );
        insert att2;
 
        
 
    }
    static testMethod void myTest6() {
        List<RecordType> rectIE = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Customer IE'];
        Account accIE = new Account(
            Name = '*',
            RecordTypeId = rectIE[0].Id,
            OwnerId = UserInfo.getUserId(),
            DivisionName__c='Customer IE',
            FacilityName__c='abc',
            PostCode__c='000000'
        );
        insert accIE; 
        Contact con = new Contact();
        con.LastName = 'test';
        con.AccountId = accIE.Id;
        con.MobilePhone = 'MobilePhoneD__c';
        con.OtherPhone = 'OtherPhoneD__c';
        con.Fax = 'FaxD__c';
        con.Email = 'EmailD__c@test.com';
        con.Phone = 'PhoneD__c';
        con.Title = 'TitleD__c';
        con.Address1__c = 'Address1D__c';
        con.Address2__c = 'Address2D__c';
        con.Address3__c = 'Address3D__c';
        con.Postcode__c = '100111';
        con.ContactStatus__c = 'ContactStatusD__c';
        con.CancelReason__c = 'CancelReasonD__c';
        con.StatusD__c = 'Pass';
        insert con;
        PriceBook2 pricebook =new PriceBook2(
            Name = 'IE'
        );
        insert pricebook;
         
        List<RecordType> rectOpp = [select id from RecordType where IsActive = true and SobjectType = 'Opportunity'];
        // 有预定下单日
        Opportunity opp = new Opportunity(
            Name = 'test opp',
            AccountId = accIE.Id,
            RecordTypeId = rectOpp[0].Id,
            OwnerId = UserInfo.getUserId(),
            StageName = 'Phase3',
            CurrencyIsoCode = 'CNY',
            ProductSegment__c = 'IE',
            CloseDate = Date.today(),
            NewInquiryDate__c = Date.today().addDays(-2),
            ExpectedOrderDate__c = Date.today().addDays(2),
            SalesChannel__c = 'direct',
            customerType__c = 'B'
        );
        insert opp;
        OpportunityContactRole role = new OpportunityContactRole(
            Role  = 'End user',
            IsPrimary = true,
            OpportunityId = opp.Id,
            ContactId = con.Id
            );
        insert role;
        Order odr = new Order(
            Name = '',
            Status = 'Draft',
            AccountId = accIE.Id,
            ApproveStatus__c = 'Draft',
            OpportunityId = opp.Id,
            EffectiveDate = Date.today(),
            EndUser__c = con.Id
        );
        insert odr;
        TradeCustomerManager__c tra = new TradeCustomerManager__c(
            OrderIdSave__c = odr.Id,
            order__c =  odr.Id
        );
        insert tra;
        Attachment att1 = new Attachment(
            Name = '军事.pdf',
            parentId = tra.Id,
            Body = EncodingUtil.base64Decode('test')
        );
        insert att1;
        Attachment att2 = new Attachment(
            Name = '个人信息.pdf',
            parentId = tra.Id,
            Body = EncodingUtil.base64Decode('test')
        );
        insert att2;
        att1.Name = 'test.pdf';
        update att1;
        delete att1;
    }
}