高章伟
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
@isTest
public class AgencyAccountCmpTest {
 
    public static Account account1 = new Account();
    public static Account account2 = new Account();
    public static Contact contact1 = new Contact();
    public static Contact contact2 = new Contact();
    public static User user = new User();
    public static Agency_Hospital_Link__c agency_hospital_link = new Agency_Hospital_Link__c();
 
    private static void testInit() {
         StaticParameter.EscapeNFM007Trigger = true;
        ControllerUtil.EscapeNFM001Trigger = true;
        // 取引先
        account1.Name = 'test1医院';
        account1.RecordTypeId = '01210000000QemG';
        insert account1;
       
 
        account2.Name = 'test1经销商';
        account2.RecordTypeId = '01210000000Qem1';
        insert account2;
        
        // 取引先責任者
        contact1.AccountId = account1.Id;
        contact1.FirstName = '責任者';
        contact1.LastName = 'test1医院';
        insert contact1;
 
        contact2.AccountId = account1.Id;
        contact2.FirstName = '責任者';
        contact2.LastName = 'test2医院';
        insert contact2;
 
        // ユーザー
        Profile p = [select Id from Profile where Name = '901_经销商活动系统'];
        user.ProfileId = p.Id;
        user.ContactId = contact2.Id;
        user.FirstName = 'ユーザー';
        user.LastName = 'テスト';
        user.Email = 'test_user@example.com';
        user.emailencodingkey='UTF-8';
        user.languagelocalekey='zh_CN';
        user.localesidkey='ja_JP';
        user.timezonesidkey='Asia/Shanghai';
        user.Username = 'test_user@example.com';
        user.Alias = 'テユ';
        user.CommunityNickname = 'テストユーザー';
        insert user;
 
        // 代理店医院
        agency_hospital_link.Name = 'test1代理店医院';
        agency_hospital_link.Hospital__c = account1.Id;
        agency_hospital_link.Agency__c = account2.Id;
        agency_hospital_link.OwnerId = user.Id;
        insert agency_hospital_link;
 
        Agency_Contact__c ac1 = new Agency_Contact__c();
        ac1.Name = 'test1のび太';
        ac1.Agency_Hospital__c = agency_hospital_link.Id;
        insert ac1;
 
        List<Account> depts = [select Id from Account where Hospital_Department_Class__c = :account1.Id];
        Account dept = depts[0];
 
        Agency_Contact__c ac2 = new Agency_Contact__c();
        ac2.Name = 'test2のび太';
        ac2.Department_Class__c = dept.Id;
        insert ac2;
    }
    
    @isTest public static void getAccountsTest() {
        testInit();
        // Implement test code
        System.runAs(user) {
            List<Agency_Contact__c> res = AgencyAccountCmp.getAccounts();
            System.assertEquals(2, res.size());
        }
    }
    
    @isTest public static void getfiledsmapTest() {
        // Implement test cod
        testInit();
        System.runAs(user) {
            Map<String,String> res = AgencyAccountCmp.getfiledsmap();
            System.assertEquals('客户人员名', res.get('Name'));
            //System.assertEquals('.客户人员名', res.get('Name'));
            System.assertEquals('医院名', res.get('Hospital_Name__c'));
        }
    }
    
    @isTest public static void searchAccountsTest() {
        // Implement test code
        testInit();
        // Implement test code
        System.runAs(user) {
            List<Agency_Contact__c> res = AgencyAccountCmp.searchAccounts('', 'test1');
            System.assertEquals(1, res.size());
        }
    }
}