/** * @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 strList = new List(); 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 data = new Map(); data = (Map)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 strList = new List(); 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 data = new Map(); data = (Map)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 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(); } @isTest static void testMethod6() { Test.startTest(); NewAgencyContactController.searchAgencyDataId(null); Test.stopTest(); } }