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
/**
 * @description       : 
 * @author            : ChangeMeIn@UserSettingsUnder.SFDoc
 * @group             : 
 * @last modified on  : 03-29-2022
 * @last modified by  : ChangeMeIn@UserSettingsUnder.SFDoc
**/
@isTest
public class NewAgencyContactControllerTest {
    @isTest
    static void testMethod1() {
        TestDataUtility.CreatePIPolicyConfiguration();
        
        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() {
        TestDataUtility.CreatePIPolicyConfiguration();
        
        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;
        System.debug('data = ' + JSON.serialize(data));
        NewAgencyContactController.Save(null, ac.Id+'');
 
        Test.stopTest();
    }
}