/* * Author: Zhang,Heyang * Created Date: 2023/08/07 * Purpose: TestClass * * */ @isTest private class LexNewAndEditRepairPIPLControllerTest { public static String ReRecordTypeId = Schema.SObjectType.Repair__c.getRecordTypeInfosByDeveloperName().get('Repair').getRecordTypeId(); public static String rectAg = Schema.SObjectType.Contact.getRecordTypeInfosByDeveloperName().get('Agency').getRecordTypeId(); @testSetup static void setupTestData(){ List rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院']; Account myAccount1 = new Account(name='Testaccount001',Dealer_discount__c =10,RecordTypeId = rectCo[0].Id,AgentCode_Ext__c = '8888888'); insert myAccount1; Product2 prod07 = new Product2(Name='Test07',ProductCode='Test07',Asset_Model_No__c = 'Test07',SFDA_Status__c = '有効',Dealer_special_Object__c = true,Packing_list_manual__c = 1,Manual_Entry__c = false); insert prod07; Product2 prod01 = new Product2(Name='Test01',ProductCode='Test01',Asset_Model_No__c = 'Test01',SFDA_Status__c = '有効',Dealer_special_Object__c = true,Packing_list_manual__c = 1,Manual_Entry__c = false); insert prod01; Contact testContacts = new Contact(email='jplumber@salesforce.com', firstname='Joe', RecordTypeId = rectAg, lastname='Plumber', AWS_Data_Id__c = 'TestContact', accountId = myAccount1.id); insert testContacts; String AsRecordTypeId = Schema.SObjectType.Asset.getRecordTypeInfosByDeveloperName().get('HPAsset').getRecordTypeId(); System.debug(AsRecordTypeId); Asset ass = new Asset(); ass.Hospital__c = myAccount1.Id; ass.RecordTypeId = AsRecordTypeId; ass.Product_Old__c = prod07.Id; ass.Product2Id = prod07.Id; ass.AccountId = myAccount1.Id; ass.Asset_Owner__c = '医院资产'; ass.Name = 'Test'; ass.SerialNumber = '1234567'; insert ass; Repair__c rep = new Repair__c(); rep.Delivered_Product__c = ass.Id; rep.Hospital__c = myAccount1.Id; rep.SalesOfficeCode_selection__c = '北京'; rep.SalesOfficeCode_selection__c = 'RC修理'; rep.work_location_select__c = '北京办事处'; rep.Repair_Detail__c = 'Test'; rep.RecordTypeId = ReRecordTypeId; rep.Agreed_Date__c = System.today(); insert rep; PI_Policy_Configuration__c config1 = new PI_Policy_Configuration__c(Sobject_Type__c = 'Repair__c'); insert config1; PI_Policy_Configuration__c config2 = new PI_Policy_Configuration__c(Sobject_Type__c = 'Repair__cV2'); insert config2; PI_Policy_Configuration__c config3 = new PI_Policy_Configuration__c(Sobject_Type__c = 'Contact'); insert config3; PI_Field_Policy_Detail__c pfpd1 = new PI_Field_Policy_Detail__c(AWS_Field_API__c = 'phone1', SF_Field_API_Name__c = 'Phone1',PI_Policy_Configuration__c = config1.Id, Enable_Encrypt__c=true); insert pfpd1; PI_Field_Policy_Detail__c pfpd2 = new PI_Field_Policy_Detail__c(AWS_Field_API__c = 'phone2', SF_Field_API_Name__c = 'Phone2',PI_Policy_Configuration__c = config2.Id, Enable_Encrypt__c=true); insert pfpd2; PI_Field_Policy_Detail__c pfpd3 = new PI_Field_Policy_Detail__c(AWS_Field_API__c = 'phone2', SF_Field_API_Name__c = 'Phone2',PI_Policy_Configuration__c = config3.Id, Enable_Encrypt__c=true); insert pfpd3; PI_Policy_Configuration__c config4 = new PI_Policy_Configuration__c(Sobject_Type__c = 'Address__c'); insert config4; PI_Policy_Configuration__c config5 = new PI_Policy_Configuration__c(Sobject_Type__c = 'Address__cV2'); insert config5; PI_Policy_Configuration__c config6 = new PI_Policy_Configuration__c(Sobject_Type__c = 'RepairSubOrder__cV2'); insert config6; PI_Policy_Configuration__c config7 = new PI_Policy_Configuration__c(Sobject_Type__c = 'RepairSubOrder__c'); insert config7; PI_Field_Policy_Detail__c pfpd4 = new PI_Field_Policy_Detail__c(AWS_Field_API__c = 'phone1', SF_Field_API_Name__c = 'Phone1',PI_Policy_Configuration__c = config4.Id, Enable_Encrypt__c=true); insert pfpd4; PI_Field_Policy_Detail__c pfpd5 = new PI_Field_Policy_Detail__c(AWS_Field_API__c = 'phone2', SF_Field_API_Name__c = 'Phone2',PI_Policy_Configuration__c = config5.Id, Enable_Encrypt__c=true); insert pfpd5; PI_Field_Policy_Detail__c pfpd6 = new PI_Field_Policy_Detail__c(AWS_Field_API__c = 'phone2', SF_Field_API_Name__c = 'Phone2',PI_Policy_Configuration__c = config6.Id, Enable_Encrypt__c=true); insert pfpd6; PI_Field_Policy_Detail__c pfpd7 = new PI_Field_Policy_Detail__c(AWS_Field_API__c = 'phone2', SF_Field_API_Name__c = 'Phone2',PI_Policy_Configuration__c = config7.Id, Enable_Encrypt__c=true); insert pfpd7; } @isTest static void tesMethod1(){ Repair__c rep = [SELECT Id,RecordTypeId,Repair_Detail__c FROM Repair__c WHERE Repair_Detail__c = 'Test' LIMIT 1]; String body='{"size":1,"totalSize":1,"done":true,"queryLocator":null,"entityTypeName":"ProfileLayout","records":[{"attributes":{"type":"ProfileLayout","url":"/services/data/v41.0/tooling/sobjects/ProfileLayout/01G10000008o6QdEAI"},"Layout":{"attributes":{"type":"Layout","url":"/services/data/v41.0/tooling/sobjects/Layout/00h10000009wV4IAAU"},"Name":"NewRepairLayout-DOJ","TableEnumOrId":"01I10000000SorSEAS"},"ProfileId":"00e10000000Y3o5AAC","Profile":{"attributes":{"type":"Profile","url":"/services/data/v41.0/tooling/sobjects/Profile/00e10000000Y3o5AAC"},"Name":"系统管理员"},"RecordTypeId":"01210000000QmS9AAK"}]}'; Test.setMock(HttpCalloutMock.class, new BaseHttpMock(body,'1','200')); System.Test.startTest(); String objectType = 'Repair__c'; List layout = MetaDataUtility.GetRecordTypePageLayout(ReRecordTypeId,objectType); LexNewAndEditBasePIPLController.initData(rep.Id,ReRecordTypeId,objectType); LexNewAndEditRepairPIPLController.initData(rep.Id,ReRecordTypeId,objectType,rep.Id); Contact con = [SELECT Id,AWS_Data_Id__c FROM Contact WHERE AWS_Data_Id__c = 'TestContact']; LexNewAndEditRepairPIPLController.getContactByAWSId(con.AWS_Data_Id__c); LexNewAndEditRepairPIPLController.EncryptUpdate(rep.Id); //测试用虚假ID LexNewAndEditRepairPIPLController.EncryptUpdate('a0J1m000001QqXk'); System.Test.stopTest(); } public class BaseHttpMock implements HttpCalloutMock { String body =''; String status = ''; String statusCode = ''; public BaseHttpMock(String body,String status,String statusCode){ this.body = body; this.status = status; this.statusCode = statusCode; } public HTTPResponse respond(HTTPRequest req) { HttpResponse res = new HttpResponse(); res.setHeader('Content-Type', 'application/json'); res.setBody(body); res.setStatus('OK'); res.setStatusCode(200); return res; } } }