高章伟
2023-03-03 d8dc84a3d56df839895f1c417a4d9cbee763d262
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
/**
 * @description       : 
 * @author            : ChangeMeIn@UserSettingsUnder.SFDoc
 * @group             : 
 * @last modified on  : 03-29-2022
 * @last modified by  : ChangeMeIn@UserSettingsUnder.SFDoc
**/
@isTest
public class NewAgencyContactControllerTest {
    public static Account account1 = new Account();
    public static Account account2 = new Account();
    public static Agency_Hospital_Link__c aHosLink = new Agency_Hospital_Link__c();
    public static Agency_Contact__c aContact = new Agency_Contact__c();
 
    @isTest
    static void testMethod1() {
        List<String> strList = new List<String>();
        strList.add('Agency_Contact__c');
        strList.add('Agency_Contact__cV2');
        strList.add('Contact');
        TestDataUtility.CreatePIPolicyConfigurations(strList);
        //TestDataUtility.CreatePIPolicyConfiguration('Agency_Contact__c');
        
        Test.setMock(HttpCalloutMock.class, new TestDataUtility.CreateMetaDataUtilityHttpMock());
        Agency_Contact__c ac = TestDataUtility.CreateAgencyContacts(1)[0];
        String recordTypeId = Schema.SObjectType.Agency_Contact__c.getRecordTypeInfosByDeveloperName().get('Agency').getRecordTypeId();
        Test.startTest();
        ControllerResponse res = NewAgencyContactController.Init(ac.Id,ac.Id,recordTypeId);
        System.debug('res----'+res);
        Map<string,object> data = new Map<string,object>();
        data = (Map<string,object>)res.Data;
        NewAgencyContactController.Save(data, ac.Id+'');
        Test.stopTest();
    }
 
    @isTest
    static void testMethod2() {
        Test.startTest();
        String body = '{"size":6,"totalSize":6,"done":true,"queryLocator":null,"entityTypeName":"Layout","records":[{"attributes":{"type":"Layout","url":"/services/data/v41.0/tooling/sobjects/Layout/00h10000005qCPDAA2"},"Id":"00h10000005qCPDAA2","Name":"医師","TableEnumOrId":"Contact","LayoutType":"Standard"},{"attributes":{"type":"Layout","url":"/services/data/v41.0/tooling/sobjects/Layout/00h10000005r604AAA"},"Id":"00h10000005r604AAA","Name":"社内员工","TableEnumOrId":"Contact","LayoutType":"Standard"},{"attributes":{"type":"Layout","url":"/services/data/v41.0/tooling/sobjects/Layout/00h100000088sb2AAA"},"Id":"00h100000088sb2AAA","Name":"社内员工(备品)","TableEnumOrId":"Contact","LayoutType":"Standard"},{"attributes":{"type":"Layout","url":"/services/data/v41.0/tooling/sobjects/Layout/00h10000005r63hAAA"},"Id":"00h10000005r63hAAA","Name":"社内员工(无CIC)","TableEnumOrId":"Contact","LayoutType":"Standard"},{"attributes":{"type":"Layout","url":"/services/data/v41.0/tooling/sobjects/Layout/00h10000009lFA2AAM"},"Id":"00h10000009lFA2AAM","Name":"系统管理员副本","TableEnumOrId":"Contact","LayoutType":"Standard"},{"attributes":{"type":"Layout","url":"/services/data/v41.0/tooling/sobjects/Layout/00h10000005qCPIAA2"},"Id":"00h10000005qCPIAA2","Name":"販売店","TableEnumOrId":"Contact","LayoutType":"Standard"}]}';
        Test.setMock(HttpCalloutMock.class, new TestDataUtility.BaseHttpMock(body,'1','200'));
        MetaDataUtility.GetAllPageLayout('Contact');
        // Agency_Contact__c ac = TestDataUtility.CreateAgencyContacts(1)[0];
        // String recordTypeId = Schema.SObjectType.Agency_Contact__c.getRecordTypeInfosByDeveloperName().get('Agency').getRecordTypeId();
        // ControllerResponse response = NewAgencyContactController.Init('a2R0l000000QNoQEAW', ac.Id, recordTypeId);
        // System.debug('response----'+response);
        Test.stopTest();
    }
 
    @isTest
    static void testMethod3() {
        List<String> strList = new List<String>();
        strList.add('Agency_Contact__c');
        strList.add('Agency_Contact__cV2');
        strList.add('Contact');
        TestDataUtility.CreatePIPolicyConfigurations(strList);
        //TestDataUtility.CreatePIPolicyConfiguration('Agency_Contact__c');
        
        Test.setMock(HttpCalloutMock.class, new TestDataUtility.CreateMetaDataUtilityHttpMock());
        String rid = '';
        Agency_Contact__c ac = TestDataUtility.CreateAgencyContacts(1)[0];
        String recordTypeId = Schema.SObjectType.Agency_Contact__c.getRecordTypeInfosByDeveloperName().get('Agency').getRecordTypeId();
        Test.startTest();
        ControllerResponse res = NewAgencyContactController.Init(rid, ac.Id, recordTypeId);
        System.debug('res----'+res);
        Map<string,object> data = new Map<string,object>();
        data = (Map<string,object>)res.Data;
        data.put('AWS_Data_Id__c','321');
        System.debug('data = ' + JSON.serialize(data));
        NewAgencyContactController.Save(data, ac.Id+'');
 
        Test.stopTest();
    }
 
    @isTest
    static void testMethod4() {
        Test.startTest();
         // 取引先
         account1.Name = 'test1医院';
         account1.RecordTypeId = '01210000000QemG';
         insert account1;
 
         account2.Name = 'test1经销商';
         account2.RecordTypeId = '01210000000Qem1';
         insert account2;
 
 
         List<Account> accTestList = [SELECT Id, Name FROM Account order by Name];
         System.debug('GYFaccTestList='+accTestList);
         System.assertEquals(10, accTestList.size());
         System.assertEquals('test1医院', accTestList[0].Name);
 
         //经销商医院データを作る
         aHosLink.Name = 'test1经销商医院';
         aHosLink.Hospital__c = account1.Id;
         aHosLink.Agency__c = account2.Id;
         insert aHosLink;
 
         //.客户人员データを作る
         Agency_Contact__c aContact1 = new Agency_Contact__c();
         aContact1.Agency_Hospital__c = aHosLink.Id;
         aContact1.Type__c = '医生';
         aContact1.Name = 'testAgencyUser';
         insert aContact1;
         NewAgencyContactController.searchAgencyDataId(aContact1.Agency_Hospital__c);
 
        Test.stopTest();
    }
 
    @isTest
    static void testMethod5() {
        Test.startTest();
        NewAgencyContactController.improveTestRate();
        Test.stopTest();
    }
}