@isTest
private class LexNewAndEditInquiryPIPLControllerTest {
    public static String rectAg = Schema.SObjectType.Contact.getRecordTypeInfosByDeveloperName().get('Agency').getRecordTypeId();
    @testSetup
    static void setupTestData(){
        List<RecordType> 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;
        Contact testContacts = new Contact(email='jplumber@salesforce.com', firstname='Joe', RecordTypeId = rectAg, lastname='Plumber', AWS_Data_Id__c = 'TestContact', accountId = myAccount1.id);
        insert testContacts;

        Inquiry_form__c inq = new Inquiry_form__c();
        inq.Name = '超声';
        inq.Request1__c = '需要报价';
        inq.Product1__c = '超声';
        inq.Opportunity_Division__c = '询价';
        insert inq;

        PI_Policy_Configuration__c config1 = new PI_Policy_Configuration__c(Sobject_Type__c  = 'Inquiry_form__c');
        insert config1;
        PI_Policy_Configuration__c config2 = new PI_Policy_Configuration__c(Sobject_Type__c  = 'Inquiry_form__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;
    }
    @isTest
    static void tesMethod1(){
        Inquiry_form__c inq = [SELECT Id FROM Inquiry_form__c WHERE Name = '超声' LIMIT 1];
        String body='{"size":3,"totalSize":3,"done":true,"queryLocator":null,"entityTypeName":"Layout","records":[{"attributes":{"type":"Layout","url":"/services/data/v41.0/tooling/sobjects/Layout/00h10000008mPbSAAU"},"Id":"00h10000008mPbSAAU","Name":"会议询问单 布局","TableEnumOrId":"01I100000016m7WEAQ","LayoutType":"Standard"},{"attributes":{"type":"Layout","url":"/services/data/v41.0/tooling/sobjects/Layout/00h10000009lIArAAM"},"Id":"00h10000009lIArAAM","Name":"服务","TableEnumOrId":"01I100000016m7WEAQ","LayoutType":"Standard"},{"attributes":{"type":"Layout","url":"/services/data/v41.0/tooling/sobjects/Layout/00h10000009lIAwAAM"},"Id":"00h10000009lIAwAAM","Name":"营业","TableEnumOrId":"01I100000016m7WEAQ","LayoutType":"Standard"}]}';
        Test.setMock(HttpCalloutMock.class, new BaseHttpMock(body,'1','200'));

        System.Test.startTest();
        String objectType = 'Inquiry_form__c';
        List<Metadata.LayoutSection> layout = MetaDataUtility.GetRecordTypePageLayout('',objectType);
        LexNewAndEditBasePIPLController.initData(inq.Id,'',objectType);
        LexNewAndEditInquiryPIPLController.initData(inq.Id,'',objectType);
        Account departmentInfo = [SELECT Id FROM Account where name='Testaccount001' Limit 1];
        LexNewAndEditInquiryPIPLController.getAccountByHospitalName(departmentInfo.Id);
        Contact con = [SELECT Id FROM Contact where lastname='Plumber' Limit 1];
        LexNewAndEditInquiryPIPLController.getContactById(con.Id);
        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;
        }
    }


}