高章伟
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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
/**
 * This class contains unit tests for validating the behavior of Apex classes
 * and triggers.
 *
 * Unit tests are class methods that verify whether a particular piece
 * of code is working properly. Unit test methods take no arguments,
 * commit no data to the database, and are flagged with the testMethod
 * keyword in the method definition.
 *
 * All test methods in an organization are executed whenever Apex code is deployed
 * to a production organization to confirm correctness, ensure code
 * coverage, and prevent regressions. All Apex classes are
 * required to have at least 75% code coverage in order to be deployed
 * to a production organization. In addition, all triggers must have some code coverage.
 * 
 * The @isTest class annotation indicates this class only contains test
 * methods. Classes defined with the @isTest annotation do not count against
 * the organization size limit for all Apex scripts.
 *
 * See the Apex Language Reference for more information about Testing and Code Coverage.
 */
@isTest
private class QISTriggerTest {
 
    static testMethod void myUnitTest() {
        QIS_Report__c qr = new QIS_Report__c(
            RC__c = UserInfo.getUserId(),
            Photo_1__c = '<img src="http://www.google.co.jp/img1" />',
            Photo_2__c = '<img src="http://www.google.co.jp/img2" />',
            Photo_3__c = '<img src="http://www.google.co.jp/img3" />',
            Photo_4__c = '<img src="http://www.google.co.jp/img4" />',
            Damage_For_Doc_Or_Pat__c = '有',
            Relation_With_The_Problem__c = '有可能',
            Report_For_Goz__c = '不知道',
            Name = 'QIS012345',
            BusinessAssistantNo__c = UserInfo.getUserId(),
            QIS_Submit_day__c = Date.Today()
        );
        insert qr;
        
        qr = [select Photo_1_Text__c, Photo_2_Text__c, Photo_3_Text__c, Photo_4_Text__c from QIS_Report__c where Id = :qr.Id];
        System.assertNotEquals(null, qr.Photo_1_Text__c);
        System.assertNotEquals(null, qr.Photo_2_Text__c);
        System.assertNotEquals(null, qr.Photo_3_Text__c);
        System.assertNotEquals(null, qr.Photo_4_Text__c);
    }
 
    static testMethod void triggerTest() {
        User us = new User(Test_staff__c = true, LastName = 'TestMao2', FirstName = 'TestMaoF2',
                Alias = 'hp2', CommunityNickname = 'TestMao2', Email = 'Test@sunbridge.com',
                Username = 'Test2211@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP',
                TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja',
                ProfileId = System.Label.ProfileId_SystemAdmin,
                Dept__c = '医疗华北营业本部', Province__c = '北京市',Job_Category__c='销售服务');
        insert us;
        User hpOwner = new User(Test_staff__c = true, LastName = 'TestMao1', FirstName = 'TestMaoF1',
                Alias = 'hp1', CommunityNickname = 'TestMao1', Email = 'Test1@sunbridge.com',
                Username = 'Test1122@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP',
                TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja',
                ProfileId = System.Label.ProfileId_SystemAdmin,
                Dept__c = '医疗华北营业本部', Province__c = '北京市',Job_Category__c='销售市场');
        insert hpOwner;
        System.runAs(us) {
            OlympusCalendar__c oly1 = new OlympusCalendar__c(Date__c=Date.valueOf('2030-12-17'));
            insert oly1;
            OlympusCalendar__c oly2 = new OlympusCalendar__c(Date__c=Date.valueOf('2030-12-17'));
            insert oly2;
            OlympusCalendar__c oly3 = new OlympusCalendar__c(Date__c=Date.valueOf('2030-12-17'));
            insert oly3;
 
            QIS_Report__c qr = new QIS_Report__c(
                RC__c = hpOwner.Id,
                Photo_1__c = '<img src="http://www.google.co.jp/img1" />',
                Photo_2__c = '<img src="http://www.google.co.jp/img2" />',
                Photo_3__c = '<img src="http://www.google.co.jp/img3" />',
                Photo_4__c = '<img src="http://www.google.co.jp/img4" />',
                Damage_For_Doc_Or_Pat__c = '有',
                Relation_With_The_Problem__c = '有可能',
                Report_For_Goz__c = '不知道',
                Name = 'QIS012345',
                BusinessAssistantNo__c = us.Id,
                QIS_Submit_day__c = Date.Today()
            );
            insert qr;
 
            qr.RC__c = us.Id;
            update qr;
 
            System.Test.startTest();
 
            us.Province__c = '河南省';
            update us;
            update qr;
 
            us.Province__c = '辽宁省';
            update us;
            update qr;
 
            us.Province__c = '海南省';
            update us;
            update qr;
 
            us.Province__c = '四川省';
            update us;
            update qr;
 
            us.Province__c = '安徽省';
            update us;
            //update qr;
            System.Test.stopTest();
        }
    }
    //2020/11/20 songxiaoqi  start
    static testMethod void ETcTest(){
        User us = new User(Test_staff__c = true, LastName = 'TestMao2', FirstName = 'TestMaoF2',
                Alias = 'hp2', CommunityNickname = 'TestMao2', Email = 'Test@sunbridge.com',
                Username = 'Test2211@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP',
                TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja',
                ProfileId = System.Label.ProfileId_SystemAdmin,
                Dept__c = '医疗华北营业本部', Province__c = '北京市',Job_Category__c='销售服务');
        insert us;
        User hpOwner = new User(Test_staff__c = true, LastName = 'TestMao1', FirstName = 'TestMaoF1',
                Alias = 'hp1', CommunityNickname = 'TestMao1', Email = 'Test1@sunbridge.com',
                Username = 'Test1122@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP',
                TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja',
                ProfileId = System.Label.ProfileId_SystemAdmin,
                Dept__c = '医疗华北营业本部', Province__c = '北京市',Job_Category__c='销售市场');
        insert hpOwner;
        System.runAs(us) {
            OlympusCalendar__c oly1 = new OlympusCalendar__c(Date__c=Date.valueOf('2030-12-17'));
            insert oly1;
            OlympusCalendar__c oly2 = new OlympusCalendar__c(Date__c=Date.valueOf('2030-12-17'));
            insert oly2;
            OlympusCalendar__c oly3 = new OlympusCalendar__c(Date__c=Date.valueOf('2030-12-17'));
            insert oly3;
 
            QIS_Report__c qr = new QIS_Report__c(
                RC__c = hpOwner.Id,
                Photo_1__c = '<img src="http://www.google.co.jp/img1" />',
                Photo_2__c = '<img src="http://www.google.co.jp/img2" />',
                Photo_3__c = '<img src="http://www.google.co.jp/img3" />',
                Photo_4__c = '<img src="http://www.google.co.jp/img4" />',
                Damage_For_Doc_Or_Pat__c = '有',
                Relation_With_The_Problem__c = '有可能',
                Report_For_Goz__c = '不知道',
                Name = 'QIS012345',
                contract_number_ET__c = 'BJ-GYN-152553',
                BusinessAssistantNo__c = us.Id,
                ET_QIS_SEND_EMAIL1__c = 'olympus@prec-tech.com.stagefull',
                ET_QIS_SEND_EMAIL2__c = 'olympus@prec-tech.com.stagefull',
                ET_QIS_SEND_EMAIL3__c = 'olympus@prec-tech.com.stagefull',
                ET_QIS_SEND_EMAIL4__c = 'olympus@prec-tech.com.stagefull',
                QIS_Submit_day__c = Date.Today()
            );
            insert qr;
 
            qr.RC__c = us.Id;
            update qr;
 
            System.Test.startTest();
 
            us.Province__c = '河南省';
            update us;
            update qr;
            System.Test.stopTest();
        }
    //2020/11/20 songxiaoqi end
    }
    //wangweipeng        LJPH-C7ZBSE          2021/10/27              start
    static testMethod void triggerTest2(){
        // 省
        Address_Level__c al = new Address_Level__c();
        al.Name = '東京';
        al.Level1_Code__c = 'CN-99';
        al.Level1_Sys_No__c = '999999';
        insert al;
        // 市
        Address_Level2__c al2 = new Address_Level2__c();
        al2.Level1_Code__c = 'CN-99';
        al2.Level1_Sys_No__c = '999999';
        al2.Level1_Name__c = '東京';
        al2.Name = '渋谷区';
        al2.Level2_Code__c = 'CN-9999';
        al2.Level2_Sys_No__c = '9999999';
        al2.Address_Level__c = al.id;
        insert al2;
 
        // 病院を作る
        Account hospital = new Account();
        hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id;
        hospital.Name = 'test hospital';
        hospital.Is_Active__c = '有効';
        hospital.Attribute_Type__c = '卫生部';
        hospital.Speciality_Type__c = '综合医院';
        hospital.Grade__c = '一级';
        hospital.OCM_Category__c = 'SLTV';
        hospital.Is_Medical__c = '医疗机构';
        hospital.State_Master__c = al.id;
        hospital.City_Master__c = al2.id;
        hospital.Town__c = '东京';
        insert hospital;
 
        // 戦略科室を得る
        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;
 
        Contact contact2 = new Contact();
        contact2.AccountId = dep.Id;
        contact2.FirstName = '責任者';
        contact2.LastName = 'test1经销商';
        insert contact2;
 
        // 产品
        Product2 pro5 = new Product2(Name='name05',IsActive=true,
                Fixture_Model_No__c='n05',Serial_Lot_No__c='S/N tracing',
                Fixture_Model_No_T__c = 'n05',
                Category2__c='耗材',
                Family='ENG',
                ProductCode_Ext__c='pc05',Manual_Entry__c=false);
        insert pro5;
 
        // 保有设备C (只有附属品 个体管理)
        Asset assetC1 = new Asset(Asset_Owner__c = 'Olympus');
        assetC1.SerialNumber = 'assetC1';
        assetC1.Name = 'assetC1';
        assetC1.AccountId = dep.Id;
        assetC1.Department_Class__c = strategicDep[0].Id;
        assetC1.Hospital__c = hospital.Id;
        assetC1.Product2Id = pro5.Id;
        assetC1.Quantity = 1;
        assetC1.Status = '有库存';
        assetC1.Manage_type__c = '个体管理';
        assetC1.Internal_asset_location__c = '北京 备品中心';
        assetC1.Loaner_accsessary__c = true;
        assetC1.Delete_Flag__c = false;
        assetC1.Freeze_sign__c = false;
        assetC1.Out_of_wh__c = 0;
 
        insert assetC1;
 
        QIS_Report__c qr = new QIS_Report__c(
            RC__c = UserInfo.getUserId(),
            Photo_1__c = '<img src="http://www.google.co.jp/img1" />',
            Photo_2__c = '<img src="http://www.google.co.jp/img2" />',
            Photo_3__c = '<img src="http://www.google.co.jp/img3" />',
            Photo_4__c = '<img src="http://www.google.co.jp/img4" />',
            Damage_For_Doc_Or_Pat__c = '有',
            Relation_With_The_Problem__c = '有可能',
            Report_For_Goz__c = '不知道',
            Name = 'QIS012345',
            contract_number_ET__c = 'BJ-GYN-152553',
            nonyushohin__c=assetC1.id,
            QIS_Submit_day__c = Date.Today()
        );
        insert qr;
 
        pro5.Category2__c='耗材';
        pro5.Family='GI';
 
        update pro5;
        update qr;
 
        qr.nonyushohin__c = null;
        update qr;
    }
    //wangweipeng        LJPH-C7ZBSE          2021/10/27              end
}