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
@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();
 
    @TestSetup 
    static void makeData(){
        TestDataUtility.CreatePIPolicyConfiguration('Agency_Contact__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,Hospital_Department_Class__c 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;
        ac2.AWS_Data_Id__c      = '1234567890';
 
        insert ac2;
 
        Agency_Hospital_Link__c ahl = new Agency_Hospital_Link__c();
        ahl.Hospital__c = dept.Hospital_Department_Class__c;
        ahl.Agency__c = dept.Id;
        insert ahl;
 
    }
    
    @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());
        }
    }
    @isTest public static void saveLogTest(){
        Map<String,Object> mso = new Map<String,Object>();
        mso.put('AWS_Data_Id__c','1234567890');
        mso.put('txId','1234567890');
        String respMsg = JSON.serialize(mso);
        AgencyAccountCmp.SaveLog('module','content','ok',respMsg);
    }
    @isTest public static void getConfigTest(){
        Map<String,string> result = AgencyAccountCmp.GetConfig();
        String sr;
        for(String str:result.keyset()){
            sr = str;
        }
        System.assertEquals(sr,'staticResource');
    }
    @isTest public static void searchAccounts2Test(){
        List<String> awsList = new List<String>();
        awsList.add('1234567890');
        List<Agency_Contact__c> acList = AgencyAccountCmp.searchAccounts2('',awsList);
    }
}