高章伟
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
@isTest
private class CampaignCostHandlerTest {
 
    @Testsetup
    static void init() {
        // Implement test code
        Campaign target1 = new Campaign();
        target1.Name = 'test campaign1';
        target1.Meeting_Type__c = '赞助会';
        target1.IsDocLOGO__c = true;
        target1.IsDocLOGO__c = true;
        target1.formality1__c  = true;
        target1.IsShowingEquipment__c = true;
        target1.IsAnimalExperience__c = true;
        target1.HostName__c = '会议主办方';
        target1.cooperatorCompany__c = '会议承办方';
        target1.isOther__c = true;
        string rec = Schema.SObjectType.Campaign.getRecordTypeInfosByDeveloperName().get('BusinessTraining').getRecordTypeId();
        target1.RecordTypeId = rec;
 
        Campaign target2 = new Campaign();
        target2.Name = 'test campaign2';
        target2.RecordTypeId = rec;
        target2.Meeting_Type__c = '共同主办会';
        target2.IsSatelliteMeeting__c  = true;
        target2.HostName__c = '会议主办方';
        target2.cooperatorCompany__c = '会议承办方';
        target2.formality1__c  = true;
        target2.isStand__c = true;
        target2.isTitle__c = true;
        insert new Campaign[] {target1, target2};
    }
 
    @isTest static void testTrigger() {
        list<Campaign> CampaignList = [select id, Name from Campaign ];
        Campaign target1 = CampaignList[0];
        Campaign_Cost__c camCost1 = new Campaign_Cost__c();
        camCost1.name = 'test1';
        camCost1.Campaign__c = target1.id;
        upsert camCost1;
        target1.Campaign_Cost__c = camCost1.id;
        upsert target1;
        camCost1.name = 'test2';
        upsert camCost1;
        delete camCost1;
        undelete camCost1;
    }
 
    @isTest static void test_checkUpdateShare() {
        User a = [select id from User where id = : userinfo.getuserid()];
        System.runAs(a) {
            list<Campaign> CampaignList = [select id, Name from Campaign ];
            Campaign target1 = CampaignList[0];
            Campaign_Cost__c camCost1 =
                new Campaign_Cost__c(name = 'test1', Campaign__c = target1.id);
            Campaign_Cost__c camCost2 =
                new Campaign_Cost__c(name = 'test2', Campaign__c = target1.id);
            Campaign_Cost__c camCost3 =
                new Campaign_Cost__c(name = 'test3', Campaign__c = target1.id);
            Campaign_Cost__c camCost4 =
                new Campaign_Cost__c(name = 'test4', Campaign__c = target1.id);
            insert new Campaign_Cost__c[] {camCost1, camCost2, camCost3, camCost4};
            user tempUser = new User();
            camCost1.Sponsor_Ones_Post__c = '1.华北';
            id tempUserId = getUser().id;
            camCost2.JingliApprovalManager__c = tempUserId;
            camCost3.BuchangApprovalManager__c = tempUserId;
            camCost4.ZongjianApprovalManager__c = tempUserId;
 
            update new Campaign_Cost__c[] {camCost1, camCost2, camCost3, camCost4};
        }
    }
 
    private static User getUser() {
        String timenow = Datetime.now().format('yyyyMMddHHmmss');
        User hpOwner = new User(Test_staff__c = true, LastName = 'TestMao', FirstName = 'TestMaoF',
                                Alias = 'hp', CommunityNickname = 'TestMao', Email = 'Test@sunbridge.com',
                                Username = 'Test' + timenow + '@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 = '北京');
        insert hpOwner;
        return hpOwner;
    }
 
}