/*
 * Author: Zhang,Heyang
 * Created Date: 2023/08/07
 * Purpose: TestClass
 *
 * */
@isTest
private class LexInspectionReportPIPLControllerTest
{
    @testSetup
    static void setupTestData() {
        PI_Policy_Configuration__c config1 = new PI_Policy_Configuration__c(Sobject_Type__c  = 'Inspection_Report__c');
        insert config1;
        PI_Policy_Configuration__c config2 = new PI_Policy_Configuration__c(Sobject_Type__c  = 'Inspection_Report__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;
        User thisUser = [ select Id from User where Id = :UserInfo.getUserId()];
        System.runAs(thisUser){
        Profile prof1 = [select Id from Profile where Name ='901_经销商社区普通权限_2重验证(ET Email)'];
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        if (rectCo.size() == 0) {
            return;
        }
        Account account1 = new Account(RecordTypeId = rectCo[0].Id, AgentCode_Ext__c = '9999900', Name = 'olympus');
		insert account1;
		Contact core = new Contact(email='jplumber@salesforce.com', firstname='Joe',lastname='Plumber',accountid=account1.id);
		insert core;
		user MyUser_Test = New User(ContactId = core.id,Alias = 'newUser',Email='newuser@testorg.com',EmailEncodingKey='UTF-8', LastName='TestUser', LanguageLocaleKey='zh_CN',LocaleSidKey='zh_CN', ProfileId = prof1.Id,TimeZoneSidKey='Asia/Shanghai', UserName='testUser@testorg.com',Work_Location__c = '上海',Job_Category__c = '销售服务');
		insert MyUser_Test;

        String RecordTypeId = Schema.SObjectType.Inspection_Report__c.getRecordTypeInfosByDeveloperName().get('ContractInspection').getRecordTypeId();
        System.debug(RecordTypeId);
        Inspection_Report__c ins = new Inspection_Report__c();
        ins.RecordTypeId = RecordTypeId;
        ins.Name = 'Test';
        ins.Hospital__c = account1.Id;
        ins.Reporter__c = MyUser_Test.Id;
        insert ins;
    }
    }
    @isTest
    static void tesMethod1(){
        Oly_TriggerHandler.bypass('ContactTriggerHandler');
        Contact con = TestDataUtility.CreateContacts(1)[0];
        con.AWS_Data_Id__c = 'davdsvgrqcx';
        con.RecordTypeId = '01210000000QfWiAAK';
        update con;

        String body='{"size":1,"totalSize":1,"done":true,"queryLocator":null,"entityTypeName":"ProfileLayout","records":[{"attributes":{"type":"ProfileLayout","url":"/services/data/v41.0/tooling/sobjects/ProfileLayout/01G1000000zCtzPEAS"},"Layout":{"attributes":{"type":"Layout","url":"/services/data/v41.0/tooling/sobjects/Layout/00h10000009eNTxAAM"},"Name":"点检报告书 布局","TableEnumOrId":"01I10000001ImJMEA0"},"ProfileId":"00e10000000Y3o5AAC","Profile":{"attributes":{"type":"Profile","url":"/services/data/v41.0/tooling/sobjects/Profile/00e10000000Y3o5AAC"},"Name":"系统管理员"},"RecordTypeId":"01210000000VLkgAAG"}]}';
        Test.setMock(HttpCalloutMock.class, new BaseHttpMock(body,'1','200'));
        System.Test.startTest();
        Inspection_Report__c ins = [SELECT Id,RecordTypeId FROM Inspection_Report__c WHERE Name = 'Test' LIMIT 1];
        LexInspectionReportPIPLController.initData(ins.Id,ins.RecordTypeId,'Inspection_Report__c');
        LexInspectionReportPIPLController.getContactByAWSId('davdsvgrqcx');
        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;
        }
    }





}