高章伟
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
/**
 * 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 ReportTriggerTest {
 
    static testMethod void myUnitTest() {
        // システム管理者
        User user = new User();
        user.LastName = '_サンブリッジ';
        user.FirstName = 'う';
        user.Alias = 'う';
        user.Email = 'olympusTest03@sunbridge.com';
        user.Username = 'olympusTest03@sunbridge.com';
        user.CommunityNickname = 'う';
        user.IsActive = true;
        user.EmailEncodingKey = 'ISO-2022-JP';
        user.TimeZoneSidKey = 'Asia/Tokyo';
        user.LocaleSidKey = 'ja_JP';
        user.LanguageLocaleKey = 'ja';
        user.ProfileId = System.Label.ProfileId_SystemAdmin;
        user.Job_Category__c = '销售推广';
        user.Province__c = '上海市';
        user.Use_Start_Date__c = Date.today().addMonths(-6);
        user.SalesManager__c = UserInfo.getUserId();
        user.BuchangApprovalManagerSales__c = UserInfo.getUserId();
        user.JingliApprovalManager__c = UserInfo.getUserId();
        user.BuchangApprovalManager__c = UserInfo.getUserId();
        user.ZongjianApprovalManager__c = UserInfo.getUserId();
        insert user;
        
        // 別ユーザ
        User user2 = new User();
        user2.LastName = '_別';
        user2.FirstName = 'ユーザ';
        user2.Alias = '別ユーザ';
        user2.Email = 'olympusTest04@sunbridge.com';
        user2.Username = 'olympusTest04@sunbridge.com';
        user2.CommunityNickname = '別ユーザ';
        user2.IsActive = true;
        user2.EmailEncodingKey = 'ISO-2022-JP';
        user2.TimeZoneSidKey = 'Asia/Tokyo';
        user2.LocaleSidKey = 'ja_JP';
        user2.LanguageLocaleKey = 'ja';
        user2.ProfileId = System.Label.ProfileId_SystemAdmin;
        user2.Job_Category__c = '销售推广';
        user2.Province__c = '上海市';
        user2.Use_Start_Date__c = Date.today().addMonths(-6);
        user2.SalesManager__c = user.Id;
        user2.BuchangApprovalManagerSales__c = user.Id;
        user2.JingliApprovalManager__c = user.Id;
        user2.BuchangApprovalManager__c = user.Id;
        user2.ZongjianApprovalManager__c = user.Id;
        insert user2;
        
        // recode type を取得
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        if (rectCo.size() == 0) {
            throw new ControllerUtil.myException('not found 病院 recodetype');
        }
        List<RecordType> rectSct = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 呼吸科'];
        if (rectSct.size() == 0) {
            throw new ControllerUtil.myException('not found 戦略科室分類 呼吸科 recodetype');
        }
        List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 消化科'];
        if (rectDpt.size() == 0) {
            throw new ControllerUtil.myException('not found 診療科 消化科 recodetype');
        }
        
        // insert
        Account company = new Account();
        company.RecordTypeId = rectCo[0].Id;
        company.Name = 'Katsu テスト';
        insert company;
        
        Account section = new Account();
        section.RecordTypeId = rectSct[0].Id;
        section.Name         = '*';
        section.Department_Class_Label__c = '消化科';
        section.ParentId                  = company.Id;
        section.Hospital_Department_Class__c = company.Id;
        NFM001Controller.isRunning = false;
        NFM001Controller.debug_msg = '';
        insert section;
 
        Account depart = new Account();
        depart.RecordTypeId = rectDpt[0].Id;
        depart.Name         = '*';
        depart.Department_Name__c  = 'NFM001TestDepart';
        depart.ParentId            = section.Id;
        depart.Department_Class__c = section.Id;
        depart.Hospital__c         = company.Id;
        NFM001Controller.isRunning = false;
        NFM001Controller.debug_msg = '';
        insert depart;
        
        // insert test
        Report__c rpt = new Report__c();
        rpt.Hospital_Department__c = depart.Id;
        rpt.OwnerId = user2.Id;
        rpt.OPD_ProductCategory1__c ='3D System';
        rpt.OPD_ProductCategory2__c ='OR Imaging Products';
        insert new Report__c[] {rpt};
        rpt = [select Id,SalesManager__c,BuchangApprovalManagerSales__c,JingliApprovalManager__c,
                                        BuchangApprovalManager__c,ZongjianApprovalManager__c 
                                   from Report__c 
                                  where Id = :rpt.Id];
        System.assertEquals(user.Id, rpt.SalesManager__c);
        System.assertEquals(user.Id, rpt.BuchangApprovalManagerSales__c);
        System.assertEquals(user.Id, rpt.JingliApprovalManager__c);
        System.assertEquals(user.Id, rpt.BuchangApprovalManager__c);
        System.assertEquals(user.Id, rpt.ZongjianApprovalManager__c);
        
        // update test
        rpt.Status__c = '申请中';
        update rpt;
        rpt = [select Id,SalesManager__c,BuchangApprovalManagerSales__c,JingliApprovalManager__c,
                                        BuchangApprovalManager__c,ZongjianApprovalManager__c 
                                   from Report__c 
                                  where Id = :rpt.Id];
        System.assertNotEquals(user.Id, rpt.SalesManager__c);
        System.assertNotEquals(user.Id, rpt.BuchangApprovalManagerSales__c);
        System.assertNotEquals(user.Id, rpt.JingliApprovalManager__c);
        System.assertNotEquals(user.Id, rpt.BuchangApprovalManager__c);
        System.assertNotEquals(user.Id, rpt.ZongjianApprovalManager__c);
        System.assertNotEquals(null, rpt.SalesManager__c);
        System.assertNotEquals(null, rpt.BuchangApprovalManagerSales__c);
        System.assertNotEquals(null, rpt.JingliApprovalManager__c);
        System.assertNotEquals(null, rpt.BuchangApprovalManager__c);
        System.assertNotEquals(null, rpt.ZongjianApprovalManager__c);
        
        rpt.OwnerId = user.Id;
        update rpt;
        rpt = [select Id,SalesManager__c,BuchangApprovalManagerSales__c,JingliApprovalManager__c,
                                        BuchangApprovalManager__c,ZongjianApprovalManager__c 
                                   from Report__c 
                                  where Id = :rpt.Id];
        System.assertEquals(UserInfo.getUserId(), rpt.SalesManager__c);
        System.assertEquals(UserInfo.getUserId(), rpt.BuchangApprovalManagerSales__c);
        System.assertEquals(UserInfo.getUserId(), rpt.JingliApprovalManager__c);
        System.assertEquals(UserInfo.getUserId(), rpt.BuchangApprovalManager__c);
        System.assertEquals(UserInfo.getUserId(), rpt.ZongjianApprovalManager__c);
    }
    
    static testMethod void customerSignTest() {
        Report__c rep1 = new Report__c();
        rep1.Customer_sigh_photo__c = 'sign test';
        rep1.Manual_Name__c = 'TEST BJ 医院 普外科 普外科';
        rep1.Evaluation_PDF_number__c = 'AAA';
        rep1.OPD_ProductCategory1__c ='3D System';
        rep1.OPD_ProductCategory2__c ='OR Imaging Products';
        insert rep1;
        
        rep1 = [select Customer_sigh_photo_txt__c from Report__c where Id = :rep1.Id];
        System.assertEquals('sign test', rep1.Customer_sigh_photo_txt__c);
    }
}