@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 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 res = AgencyAccountCmp.getAccounts(); System.assertEquals(2, res.size()); } } @isTest public static void getfiledsmapTest() { // Implement test cod testInit(); System.runAs(user) { Map 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 res = AgencyAccountCmp.searchAccounts('', 'test1'); System.assertEquals(1, res.size()); } } @isTest public static void saveLogTest(){ Map mso = new Map(); 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 result = AgencyAccountCmp.GetConfig(); String sr; for(String str:result.keyset()){ sr = str; } System.assertEquals(sr,'staticResource'); } @isTest public static void searchAccounts2Test(){ List awsList = new List(); awsList.add('1234567890'); List acList = AgencyAccountCmp.searchAccounts2('',awsList); } }