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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
@isTest
private class AccountWebServiceTest {
 
    static testMethod void myUnitTest() {
        List<RecordType> rectIE = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Customer IE'];
        Account acc1 = new Account(
            name = '*',
            RecordTypeId = rectIE[0].Id,
            OwnerId = UserInfo.getUserId(),
            DivisionName__c = 'Customer IE',
            FacilityName__c = 'abc',
            DivisionName_D__c = 'Customer IE',
            FacilityNameD__c = 'abc',
            AccountStatus__c = 'Cancel',
            PostCode__c = '123456'
        );
        Account acc2 = new Account(
            name = '*',
            RecordTypeId = rectIE[0].Id,
            OwnerId = UserInfo.getUserId(),
            DivisionName__c = 'Customer IE',
            FacilityName__c = 'abc',
            DivisionName_D__c = 'Customer IE',
            FacilityNameD__c = 'abc',
            PostCode__c = '123456'
        );
        Account acc3 = new Account(
            name = '*',
            RecordTypeId = rectIE[0].Id,
            OwnerId = UserInfo.getUserId(),
            DivisionName__c = 'Customer IE',
            FacilityName__c = 'abc',
            DivisionName_D__c = 'Customer IE',
            FacilityNameD__c = 'abc',
            CancelReason__c = 'test',
            PostCode__c = '123456'
        );
        insert new List<Account> {acc1,acc2,acc3};
        
        String rs = '';
        rs = AccountWebService.AccountCancel('12345678');
        System.assertEquals('无效的客户', rs);
        
        rs = AccountWebService.AccountCancel(acc1.Id);
        System.assertEquals('客户已经取消', rs);
        
        rs = AccountWebService.AccountCancel(acc2.Id);
        System.assertEquals('必须输入取消理由', rs);
        
        rs = AccountWebService.AccountCancel(acc3.Id);
        System.assertEquals('1', rs);
        List<Account> accList = [select Id,AccountStatus__c from Account where Id = :acc3.Id];
        System.assertEquals('Cancel', accList[0].AccountStatus__c);
    }
 
    static testMethod void myUnitTest2() {
        List<RecordType> rectIE = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Customer IE'];
        String localid = UserInfo.getUserId();
 
        Account acc1 = new Account(
            name = '*',
            RecordTypeId = rectIE[0].Id,
            OwnerId = UserInfo.getUserId(),
            DivisionName__c = 'Customer IE',
            FacilityName__c = 'abc',
            DivisionName_D__c = 'Customer IE',
            FacilityNameD__c = 'abc',
            AccountStatus__c = 'Cancel',
            PostCode__c = '123456'
        );
        insert acc1;
 
        User user = new User();
        user.LastName = 'test20201014';
        user.FirstName = 'test';
        user.Alias = 'test';
        user.Email = 'test@test.com';
        user.Username = 'test111@test222.com';
        user.CommunityNickname = 'test20201014';
        user.IsActive = true;
        user.EmailEncodingKey = 'ISO-2022-JP';
        user.TimeZoneSidKey = 'Asia/Tokyo';
        user.LocaleSidKey = 'ja_JP';
        user.LanguageLocaleKey = 'ja';
        user.ProfileId = System.Label.SystemAdmin;
        insert user;
 
        AccountTeamMember atm = new AccountTeamMember(
            AccountId = acc1.Id,
            userId = localid,
            teamMemberRole = 'Sales Manager'
        );
        AccountTeamMember atm2 = new AccountTeamMember(
            AccountId = acc1.Id,
            userId = user.Id,
            teamMemberRole = 'Sales Manager'
        );
        insert new AccountTeamMember[] {atm,atm2};
 
        String rs = '';
        rs = AccountWebService.UpdateShare(acc1.Id, localid, user.Id);
        System.assertEquals('1', rs);
 
        List<AccountTeamMember> atmList = [select Id, AccountAccessLevel from AccountTeamMember where Id = :atm.Id];
        System.assertEquals('Edit', atmList[0].AccountAccessLevel);
    }
    // 技术服务部客户与联系人申请提交时字段验证
    static testMethod void TechnicalServiceCreated() {
        List<RecordType> rectIE = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Customer IE'];
        List<RecordType> rectBS = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Customer BS'];
        Account acc1 = new Account(
            name = '*',
            RecordTypeId = rectIE[0].Id,
            OwnerId = UserInfo.getUserId(),
            DivisionName__c = 'Customer IE',
            FacilityName__c = 'abc',
            DivisionName_D__c = 'Customer IE',
            FacilityNameD__c = 'abc',
            AccountStatus__c = 'Cancel',
            PostCode__c = '123456',
            serviceCreate__c = true
        );
        Account acc2 = new Account(
            name = '*',
            RecordTypeId = rectBS[0].Id,
            OwnerId = UserInfo.getUserId(),
            //DivisionName__c = 'Customer BS',
            FacilityName__c = 'abc'
        );
        Account acc3 = new Account(
            name = '*',
            RecordTypeId = rectIE[0].Id,
            OwnerId = UserInfo.getUserId(),
            DivisionName__c = 'Customer IE',
            FacilityName__c = 'abc',
            DivisionName_D__c = 'Customer IE',
            FacilityNameD__c = 'abc',
            CancelReason__c = 'test',
            PostCode__c = '123456'
        );
        User hpOwner = new User( 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 = System.Label.SystemAdmin2,MarketingStrategy__c =true);
        insert hpOwner;
        System.runAs(hpOwner){
            insert new List<Account> {acc1,acc2,acc3};
            
            // insert dealer;
            Contact core = new Contact(email='jplumber@salesforce.com', firstname='Joe',lastname='Plumber',accountid=acc1.id);
            insert core;
 
            String rs = '';
            // rs = AccountWebService.AccountCancel('12345678');
            // System.assertEquals('无效的客户', rs);
            
            rs = AccountWebService.RequiredField(acc1.Id);
            // System.assertEquals('客户已经取消', rs);
            
            rs = AccountWebService.RequiredField(acc2.Id);
            // System.assertEquals('必须输入取消理由', rs);
            rs = AccountWebService.ContactRequiredField(core.Id);
            // rs = AccountWebService.AccountCancel(acc3.Id);
            // System.assertEquals('1', rs);
            // List<Account> accList = [select Id,AccountStatus__c from Account where Id = :acc3.Id];
            // System.assertEquals('Cancel', accList[0].AccountStatus__c);
        }
    }
}