buli
2022-05-14 ead4df22dca33a867279471821ca675f91dec760
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
@isTest
private class UserFaultInfoHandlerTest {
 
    public static TS_Repair__c tsr;
    public static TS_Repair__c tsr2;
    public static BusinessActivity__c ba1;
    public static BusinessActivity__c ba2;
    public static BusinessActivity__c ba3;
    public static BusinessActivity__c ba4;
 
    public static User_FaultInfo__c uf1;
    public static User_FaultInfo__c uf2;
    public static User_FaultInfo__c uf3;
 
    public static FailureAsset__c fa1;
    public static FailureAsset__c fa2;
    public static FailureAsset__c fa3;
    static void basicData() {
 
        List<RecordType> rectDealer = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Dealer'];
        Profile prof = [select Id from Profile where Name ='SSBG DEALER IE'];
        Account dealer = new Account();
        dealer.Name = 'test dealer';
        dealer.RecordTypeId = rectDealer[0].Id;
        dealer.ProductSegment__c = 'BS';
        dealer.PostCode__c='000000';
        insert dealer;
        Contact core = new Contact(email='jplumber@salesforce.com', firstname='Joe',lastname='Plumber',accountid=dealer.id);
        insert core;
        User testUser = New User(ContactId = core.id,Alias = 'newUser',Email='newuser@testorg.com',EmailEncodingKey='UTF-8', LastName='TestUser', LanguageLocaleKey='zh_CN',LocaleSidKey='zh_CN', ProfileId = '00e28000001sZE6',TimeZoneSidKey='Asia/Shanghai', UserName='testUser01@prectech.com');
 
        uf1 = new User_FaultInfo__c();
        // uf1.ASSIGNED_TO__c = UserD().Id;
        // uf1.Interactions__c = 'TEST01';
        insert uf1;
 
        tsr = new TS_Repair__c();
        tsr.TSReportDate__c = Date.today();
        insert tsr;    
        tsr2 = new TS_Repair__c();
        tsr2.TSReportDate__c = Date.today();
        insert tsr2;
        fa1 = new FailureAsset__c();
        fa1.model__c = 'test1';
        fa1.FAUserFaultInfo__c = uf1.Id;
        insert fa1;
        ba1 = new BusinessActivity__c();
        ba1.BusinessATS__c = tsr.Id;
        ba1.workingHours__c = 2;
        ba1.BusinessAApprovalOpinion__c = '同意';
        ba1.User_FaultInfo__c = uf1.Id;
        insert ba1;
        ba4 = new BusinessActivity__c();
        ba4.BusinessATS__c = tsr.Id;
        ba4.workingHours__c = 7;
        ba4.BusinessAApprovalOpinion__c = '';
        ba4.User_FaultInfo__c = uf1.Id;
        insert ba4;
 
        uf2 = new User_FaultInfo__c();
        insert uf2;
        fa2 = new FailureAsset__c();
        fa2.model__c = 'test2';
        fa2.FAUserFaultInfo__c = uf2.Id;
        insert fa2;
        ba2 = new BusinessActivity__c();
        ba2.BusinessATS__c = tsr2.Id;
        ba2.workingHours__c = 2;
        ba2.User_FaultInfo__c = uf2.Id;
        insert ba2;
 
        uf3 = new User_FaultInfo__c();
        insert uf3;
        fa3 = new FailureAsset__c();
        fa3.model__c = 'test3';
        fa3.FAUserFaultInfo__c = uf3.Id;
        insert fa3;
        ba3 = new BusinessActivity__c();
        ba3.BusinessATS__c = tsr2.Id;
        ba3.workingHours__c = 2;
        ba3.User_FaultInfo__c = uf3.Id;
        insert ba3;
 
        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 = ba2.Id,
            Body = EncodingUtil.base64Decode('test')
        );
        insert att2;
 
    }
    static testMethod void testMethod1() {
        basicData();
        User user2 = UserD();
        uf1.ASSIGNED_TO__c = user2.Id;
        uf1.SEND_TO_CUSTOMER__c = true;
        uf1.INTERNAL_ONLY__c = true;
        uf1.Interactions__c = 'TEST';
        update uf1;
    }
 
    static testMethod void testMethod2() {
        // basicData();
        // User user2 = UserD();
        // uf1.ASSIGNED_TO__c = user2.Id;
        // uf1.SEND_TO_CUSTOMER__c = true;
        // uf1.INTERNAL_ONLY__c = true;
        // // uf1.Interactions__c = 'TEST';
        // update uf1;
 
        User_FaultInfo__c ufn = new User_FaultInfo__c();
        ufn.ASSIGNED_TO__c = UserD().Id;
        ufn.Interactions__c = 'TEST01';
        insert ufn;
    }
    
 
    public static User UserD(){
        User user2 = new User();
        user2.LastName = 'test2';
        user2.FirstName = 'test2';
        user2.Alias = 'test2';
        user2.Email = 'test2@test.com';
        user2.Username = 'Xin_Prectech@olympus.com.cn';
        user2.CommunityNickname = 'test2';
        user2.IsActive = true;
        user2.EmailEncodingKey = 'ISO-2022-JP';
        user2.TimeZoneSidKey = 'Asia/Tokyo';
        user2.LocaleSidKey = 'ja_JP';
        user2.LanguageLocaleKey = 'ja';
        user2.ProfileId = '00e28000001sZE6';//System.Label.SystemAdmin;
        insert user2;
 
        return user2;
    }    
}