高章伟
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
@isTest
private class Event_ConfirmationTest {
    
    private static Event e{get;set;}
    private static User u1{get;set;}
    private static User u2{get;set;}
    private static User u3{get;set;}
    private static User u4{get;set;}
    
    /**
     * 初期処理.
     */
    private static void init() {
        Profile p = [select id from Profile where id =:System.Label.ProfileId_SystemAdmin];
        
        u1 = new User(Test_staff__c = true);
        u1.LastName = '_サンブリッジ';
        u1.FirstName = 'あ';
        u1.Alias = 'あ';
        u1.Email = 'olympusTest01@sunbridge.com';
        u1.Username = 'olympusTest01@sunbridge.com';
        u1.CommunityNickname = 'olympusTest01@sunbridge.com';
        u1.IsActive = true;
        u1.EmailEncodingKey = 'ISO-2022-JP';
        u1.TimeZoneSidKey = 'Asia/Tokyo';
        u1.LocaleSidKey = 'ja_JP';
        u1.LanguageLocaleKey = 'ja';
        u1.ProfileId = p.id;
        u1.Job_Category__c = '销售服务';
        u1.Province__c = '東京';
        u1.Post__c = '部长';
        insert u1;
        
        u2 = new User(Test_staff__c = true);
        u2.LastName = '_サンブリッジ';
        u2.FirstName = 'あ';
        u2.Alias = 'あ';
        u2.Email = 'olympusTest02@sunbridge.com';
        u2.Username = 'olympusTest02@sunbridge.com';
        u2.CommunityNickname = 'olympusTest02@sunbridge.com';
        u2.IsActive = true;
        u2.EmailEncodingKey = 'ISO-2022-JP';
        u2.TimeZoneSidKey = 'Asia/Tokyo';
        u2.LocaleSidKey = 'ja_JP';
        u2.LanguageLocaleKey = 'ja';
        u2.ProfileId = p.id;
        u2.Job_Category__c = '销售服务';
        u2.Province__c = '東京';
        u2.Post__c = '经理';
        insert u2;
        
        u3 = new User(Test_staff__c = true);
        u3.LastName = '_サンブリッジ';
        u3.FirstName = 'あ';
        u3.Alias = 'あ';
        u3.Email = 'olympusTest03@sunbridge.com';
        u3.Username = 'olympusTest03@sunbridge.com';
        u3.CommunityNickname = 'olympusTest03@sunbridge.com';
        u3.IsActive = true;
        u3.EmailEncodingKey = 'ISO-2022-JP';
        u3.TimeZoneSidKey = 'Asia/Tokyo';
        u3.LocaleSidKey = 'ja_JP';
        u3.LanguageLocaleKey = 'ja';
        u3.ProfileId = p.id;
        u3.Job_Category__c = '销售服务';
        u3.Province__c = '東京';
        u3.Post__c = '';
        insert u3;
        
        u4 = new User(Test_staff__c = true);
        u4.LastName = '_サンブリッジ';
        u4.FirstName = 'あ';
        u4.Alias = 'あ';
        u4.Email = 'olympusTest04@sunbridge.com';
        u4.Username = 'olympusTest04@sunbridge.com';
        u4.CommunityNickname = 'olympusTest04@sunbridge.com';
        u4.IsActive = true;
        u4.EmailEncodingKey = 'ISO-2022-JP';
        u4.TimeZoneSidKey = 'Asia/Tokyo';
        u4.LocaleSidKey = 'ja_JP';
        u4.LanguageLocaleKey = 'ja';
        u4.ProfileId = p.id;
        u4.Job_Category__c = '销售服务';
        u4.Province__c = '東京';
        u4.Post__c = '副总监';
        insert u4;
        
        e = new Event();
        e.StartDateTime = datetime.now();
        e.EndDateTime = datetime.now();
        e.DurationInMinutes = 0;
        insert e;
    }
    
    static testMethod void myUnitTest() {
        init();
        
        List<ID> idList = new List<ID>();
        idList.add(e.id);
        System.runAs(u1) {
            Event_Confirmation.checkMinister(idList);
        }
        
        System.runAs(u2) {
            Event_Confirmation.checkMinister(idList);
        }
        
        System.runAs(u3) {
            Event_Confirmation.checkMinister(idList);
        }
        
        System.runAs(u4) {
            Event_Confirmation.checkMinister(idList);
        }
    }
    
    static testMethod void checkMinisterTest() {
        init();
        
        Date t = Date.today();
        Date t1 = t.addMonths(6);
        
        Daily_Report__c dr1 = new Daily_Report__c(
            Reported_Date__c = t1,
            Status__c = '作成中',
            Reporter__c = Userinfo.getUserId()
        );
        
        insert dr1;
        
        Event__c ec1 = new Event__c(
            Daily_Report__c = dr1.Id,
            StartDateTime__c = Datetime.newInstance(t1.year(), t1.month(), t1.day(), 10, 0, 0),
            EndDateTime__c = Datetime.newInstance(t1.year(), t1.month(), t1.day(), 11, 0, 0),
            ActivityDate__c = dr1.Reported_Date__c,
            Subject__c = 'eventc1'
        );
        insert ec1;
        
        List<ID> idList = new List<ID>();
        idList.add(ec1.id);
        
        Event_Confirmation.checkMinister(idList);
        
        System.runAs(u1) {
            Event_Confirmation.checkMinister(idList);
        }
        
        System.runAs(u2) {
            Event_Confirmation.checkMinister(idList);
        }
        
        System.runAs(u3) {
            Event_Confirmation.checkMinister(idList);
        }
        
        System.runAs(u4) {
            Event_Confirmation.checkMinister(idList);
        }
    }
}