Li Jun
2022-03-31 3ba0123db48f8bab81ddf0913e1b95280ef545e8
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
@isTest
private class CampaignMemberServiceControllerTest {
 
    @testSetup 
    static void makeData(){
        TestDataUtility.CreatePIPolicyConfiguration('Contact');
    }
    static void testSetupMethod() {
        RecordType rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'Hp'];
        List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName IN ('Department_GI', 'Department_BF') order by DeveloperName desc];
 
        Account acc = new Account();
        acc.RecordTypeId = rectCo.Id;
        acc.Name = 'HP test1';
        insert acc;
 
        List<Account> dept = [select Id, Name from Account where ParentId = :acc.Id and Department_Class_Label__c IN ('消化科', '呼吸科') order by Department_Class_Label__c];
 
        Account depart1 = new Account();
        depart1.RecordTypeId = rectDpt[0].Id;
        depart1.Name         = '*';
        depart1.Department_Name__c  = 'Gastoro Intestin Test';
        depart1.ParentId            = dept[0].Id;
        depart1.Department_Class__c = dept[0].Id;
        depart1.Hospital__c         = acc.Id;
 
        Account depart2 = new Account();
        depart2.RecordTypeId = rectDpt[1].Id;
        depart2.Name         = '*';
        depart2.Department_Name__c  = '診療科2';
        depart2.ParentId            = dept[1].Id;
        depart2.Department_Class__c = dept[1].Id;
        depart2.Hospital__c         = acc.Id;
        insert new Account[] {depart1, depart2};
 
        Contact con = new Contact();
        con.LastName = 'lastname2';
        con.FirstName = 'firstname2';
        con.Email = 'olympustest033@sunbridge.com';
        con.MobilePhone = '99999999';
        con.Work_Location_manual__c = 'location2';
        con.Post_picklist__c = '部长';
        con.Job_Category_picklist__c = '销售推广';
        con.Hire_date_text__c = Date.today().addMonths(-6);
        con.Gender_text__c = '男';
        con.dept__c = '服务本部';
        con.Pregnant_Rest__c = true;
 
        Contact con1 = new Contact();
        con1.LastName = 'testname2';
        con1.FirstName = 'firstname2';
        con1.Email = 'olympustest0331@sunbridge.com';
        con1.MobilePhone = '999999199';
        con1.Work_Location_manual__c = 'location2';
        con1.Post_picklist__c = '部长';
        con1.Job_Category_picklist__c = '销售推广';
        con1.Hire_date_text__c = Date.today().addMonths(-6);
        con1.Gender_text__c = '男';
        con1.dept__c = '服务本部';
        con1.Pregnant_Rest__c = true;
        insert new Contact[] {con, con1};
        RecordType oppVND = [select id from RecordType where IsActive = true and SobjectType = 'Opportunity' and DeveloperName = 'Opportunity'];
 
        Opportunity opp1 = new Opportunity(
            Name = 'test opp1',
            StageName = '引合',
            CurrencyIsoCode = 'USD',
            CloseDate = Date.today(),
            AccountId = depart1.Id,
            RecordTypeId = oppVND.Id,
            Closing_Bid_Date__c = Date.today().addDays(-5),
            Hospital__c = acc.Id,
            Competitor__c = 'A'
        );
        Opportunity opp2 = new Opportunity(
            Name = 'test opp2',
            StageName = '引合',
            CurrencyIsoCode = 'USD',
            CloseDate = Date.today(),
            AccountId = depart2.Id,
            RecordTypeId = oppVND.Id,
            Closing_Bid_Date__c = Date.today().addDays(-5),
            Hospital__c = acc.Id,
            Competitor__c = 'B'
        );
        insert new Opportunity[] {opp1, opp2};
        RecordType rectCA = [select Id from RecordType where IsActive = true and SobjectType = 'Campaign'
                             and DeveloperName = 'ServiceEngineerTraining'];
 
        Campaign cam = new Campaign();
        cam.Name = 'cam';
        cam.Name2__c = '1234';
        cam.recordtypeid = rectCA.id;
        cam.StartDate = Date.today().addDays(15);
        cam.EndDate = Date.today().addDays(18);
        cam.Lesson_Type__c = '标准';
        cam.TrainingType__c = 'BME';
        cam.Mailflg_after45__c = true;
        cam.Mailflg_cancel__c = true;
        cam.Mailflg_before15__c = true;
        cam.Mailflg_before7__c = true;
        cam.Mailflg_after3__c = true;
        insert cam;
        CampaignMember__c cm1 = new CampaignMember__c();
 
        list<CampaignMember__c> cmList = new list<CampaignMember__c>();
        cmList.add(cm1);
 
        cm1.Department__c = depart1.Name;
        cm1.Department_ID__c = depart1.Id;
        cm1.Contact__c = con.LastName;
        cm1.Contact_ID__c = con.Id;
        cm1.Campaign__c = cam.id;
 
 
 
        upsert cmList;
 
 
    }
    @isTest static void test_method_one() {
        testSetupMethod();
        list<Campaign> camlist = [select id from campaign];
        Campaign cam = camlist[0];
        PageReference page = new PageReference('/apex/CampaignMemberService?id=' + cam.Id);
        System.Test.setCurrentPage(page);
        CampaignMemberServiceController cmc = new CampaignMemberServiceController();
        //初始化测试
        cmc.init();
 
        cmc.getLineInfoListSize();
 
        cmc.addLine();
 
        cmc.checkLine();
 
        cmc.lineNo = 7;
        cmc.deleteLine();
        Test.startTest();
        cmc.saveLine();
        List<CampaignMember__c> cmList = [ select id, Name, Campaign__c, Department__c, Department_ID__c, Opportunity__c, Opportunity_ID__c,
                                           Contact__c, Contact_ID__c, Type__c
                                           from CampaignMember__c
                                           where Campaign__c = :cam.Id];
 
 
        System.Test.setCurrentPage(page);
        CampaignMemberServiceController cmc2 = new CampaignMemberServiceController();
        cmc2.init();
        cmc.saveLine();
        Test.stopTest();
    }
 
    @isTest static void test_method_two() {
        testSetupMethod();
        list<Campaign> camlist = [select id from campaign];
        Campaign cam1 = camlist[0];
        RecordType rectCA = [select Id from RecordType where IsActive = true and SobjectType = 'Campaign'
                             and DeveloperName = 'ServiceEngineerTraining'];
        Test.startTest();
        Campaign cam2 = new Campaign();
        cam2.Name = 'cam';
        cam2.Name2__c = '1234';
        cam2.recordtypeid = rectCA.id;
        cam2.Lesson_Type__c = '标准';
        cam2.TrainingType__c = 'BME';
        cam2.StartDate = Date.today().addDays(15);
        cam2.EndDate = Date.today().addDays(18);
 
        insert cam2;
 
 
        Contact con1 = new Contact();
        con1.LastName = 'testname2';
        con1.FirstName = 'firstname2';
        con1.Email = 'olympustest0331@sunbridge.com';
        con1.MobilePhone = '999999199';
        con1.Work_Location_manual__c = 'location2';
        con1.Post_picklist__c = '部长';
        con1.Job_Category_picklist__c = '销售推广';
        con1.Hire_date_text__c = Date.today().addMonths(-6);
        con1.Gender_text__c = '男';
        con1.dept__c = '服务本部';
        con1.Pregnant_Rest__c = true;
        con1.Campaign__c = cam1.id;
        insert con1;
 
        Test.stopTest();
        PageReference page = new PageReference('/apex/CampaignMemberService?id=' + cam2.Id);
        System.Test.setCurrentPage(page);
        CampaignMemberServiceController cmc = new CampaignMemberServiceController();
        //初始化测试
        cmc.init();
        list<Account> departList = [select id, Name from Account];
        Account depart1 = departList[0];
        cmc.lineInfoList[2].cm.Department__c = depart1.Name;
        cmc.lineInfoList[2].cm.Department_ID__c = depart1.Id;
        cmc.lineInfoList[2].cm.Contact__c = con1.LastName;
        cmc.lineInfoList[2].cm.Contact_ID__c = con1.Id;
        cmc.saveLine();
        cmc.saveflg = '1';
        cmc.checkLine();
        cmc.errorStr = '1';
        cmc.checkLine();
 
    }
 
}