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
@isTest
private class CampaignMemberControllerTest {
    @TestSetup
    static void setUp(){
        TestDataUtility.CreatePIPolicyConfigurations( new string[]{'Contact'});
    }
    
    @isTest 
    static void test_method_one() {
        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;
        insert con;
 
        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};
 
        Campaign cam = new Campaign();
        cam.Name = 'cam';
        cam.StartDate = Date.today().addDays(-15);
        cam.EndDate = Date.today().addDays(18);
        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;
        cam.HostName__c = '111';
        cam.cooperatorCompany__c = '222';
        cam.status = '公开中';
        insert cam;
 
        PageReference page = new PageReference('/apex/CampaignMember?id=' + cam.Id);
        System.Test.setCurrentPage(page);
        CampaignMemberController cmc = new CampaignMemberController();
        //初始化测试
        cmc.init();
 
        cmc.getLineInfoListSize();
 
        cmc.addLine();
 
        cmc.checkLine();
        Test.startTest();
        cmc.lineNo = 7;
        cmc.deleteLine();
 
        cmc.lineInfoList[0].cm.Department__c = depart1.Name;
        cmc.lineInfoList[0].cm.Department_ID__c = depart1.Id;
        cmc.lineInfoList[0].cm.Contact__c = con.LastName;
        cmc.lineInfoList[0].cm.Contact_ID__c = con.Id;
        cmc.lineInfoList[0].cm.Opportunity__c = opp1.Name;
        cmc.lineInfoList[0].cm.Opportunity_ID__c = opp1.Id;
        cmc.lineInfoList[0].cm.Type__c = '参会人员';
 
        cmc.saveLine();
        //System.assertEquals('', ApexPages.getMessages()[0].getDetail());
        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.assertEquals(1, cmList.size());
 
        System.Test.setCurrentPage(page);
        CampaignMemberController cmc2 = new CampaignMemberController();
        cmc.init();
        Test.stopTest();
    }
 
}