涂煌豪
2022-04-02 34930270dfb667089047eda39473ff23ac24e060
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
@isTest
private class ContactTriggerHandlerTest {
 
    public static Account account1 = new Account();
    public static Account account2 = new Account();
    public static Contact contact1 = new Contact();
    public static Contact contact2 = new Contact();
    
    @isTest static void test_method_one() {
        List<RecordType> HPrectCo = [select Id, Name, DeveloperName from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'];
        List<RecordType> GIrectCo = [select Id, Name, DeveloperName from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_Class_GI'];
        List<RecordType> DoctorrectCo = [select Id, Name, DeveloperName from RecordType where IsActive = true and SobjectType = 'Contact' and DeveloperName = 'Doctor'];
        if (HPrectCo.size() == 0) {
            throw new ControllerUtil.myException('not found HP recordtype');
        }
        if (GIrectCo.size() == 0) {
            throw new ControllerUtil.myException('not found Department_Class_GI recordtype');
        }
        if (DoctorrectCo.size() == 0) {
            throw new ControllerUtil.myException('not found Doctor recordtype');
        }
        // 取引先
        account1.Name = 'test1医院';
        // account1.RecordTypeId = '01210000000QemG';
        account1.RecordTypeId = HPrectCo[0].Id;
        insert account1;
        
        // 取引先責任者
        contact1.AccountId = account1.Id;
        contact1.FirstName = '責任者';
        contact1.LastName = 'test1医院';
        Account dept = [select Id from Account where RecordTypeId =: GIrectCo[0].Id];
        contact1.Strategic_dept_Class__c = dept.Id;
        contact1.MobilePhone = '13409507069';
        // contact1.RecordTypeId = '01210000000QfWdAAK';
        contact1.RecordTypeId = DoctorrectCo[0].Id;
        contact1.UnifiedI_Contact_ID__c = '100000';
        insert contact1;
        MeetingManagement__c a = 
        new MeetingManagement__c(Contact__c =contact1.id
            ,pollingTime__c = 1,
            VisitTime__c= 1,InspectTime__c =1,
            InspectEquipmentTime__c = 1,TeachingTime__c =1 ,
            MaintenanceReportTime__c =1
         );
        insert a;
        update contact1;
        List<Agency_Contact__c> agency_contact = [Select Id, Name,Contact__c from Agency_Contact__c];
 
        System.assertEquals(agency_contact.size(), 1);
        System.assertEquals(agency_contact[0].Contact__c, contact1.Id);
 
        delete contact1;
 
        agency_contact = [Select Id, Name from Agency_Contact__c];
 
        System.assertEquals(agency_contact.size(), 0);
    }
    @isTest
    static void test_method_two(){
        List<RecordType> AgencyrectCo1 = [select Id, Name, DeveloperName from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'Agency'];
        if (AgencyrectCo1.size() == 0) {
            throw new ControllerUtil.myException('not found AccountAgency recordtype');
        }
        List<RecordType> AgencyrectCo2 = [select Id, Name, DeveloperName from RecordType where IsActive = true and SobjectType = 'Contact' and DeveloperName = 'Agency'];
        if (AgencyrectCo2.size() == 0) {
            throw new ControllerUtil.myException('not found ContactAgency recordtype');
        }
        account2.Name = 'test2 经销商';
        // account2.RecordTypeId = '01210000000Qem1';
        account2.RecordTypeId = AgencyrectCo1[0].Id;
        insert account2;
 
        contact2.FirstName = 'test';
        contact2.LastName = 'Data';
        // contact2.RecordTypeId = '01210000000QfWi';
        contact2.RecordTypeId = AgencyrectCo2[0].Id;
        contact2.AccountId = account2.Id;
        contact2.Agency_User__c = true;
        contact2.MobilePhone = '18999999999';
        insert contact2;
        contact2.MobilePhone = '1899999999A';
        update contact2; 
 
        Contact contact3 = new Contact();
        contact3.FirstName = 'test';
        contact3.LastName = 'Data';
        // contact3.RecordTypeId = '01210000000QfWi';
        contact3.RecordTypeId = AgencyrectCo2[0].Id;
        contact3.AccountId = account2.Id;
        // contact3.Agency_User__c = true;
        contact3.Ignore_Same_Name__c = true;
        contact3.MobilePhone = '';
        insert contact3;
        List<account> accList  = [select Dealer_Num__c From account];
        system.assertEquals(accList[0].Dealer_Num__c,1);
 
        contact2.Agency_User__c = false;
        update contact2;
        List<account> accList2  = [select Dealer_Num__c From account];
        system.assertEquals(accList2[0].Dealer_Num__c,0);
 
        contact2.Agency_User__c = true;
        update contact2;
        delete contact2;
        List<account> accList3  =  [select Dealer_Num__c From account];
        system.assertEquals(accList3[0].Dealer_Num__c,0);
    }
}