/*
 * Author: Guo, Aline Yaying
 * Created Date: 03/22/2022
 * Purpose: Test Class
 * History: 
 *      03/22/2022 - Guo, Aline Yaying - Initial Code.
 * 
 * */
@isTest
private class NewAndEditReportControllerTest {
    @TestSetup
    static void makeData(){
        List<String> strList = new List<String>();
        strList.add('Report__c');
        strList.add('Contact');
        strList.add('Agency_Contact__c');
        TestDataUtility.CreatePIPolicyConfigurations(strList);
    }
    static testMethod void testMethod1() {
     
        Test.setMock(HttpCalloutMock.class, new TestDataUtility.CreateMetaDataUtilityHttpMock());
        RecordType rtId1 = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        Account acc1 = new Account();
        acc1.Name = 'Test1 病院';
        acc1.RecordTypeId = rtId1.Id;
        insert acc1;
        RecordType rtId2 = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 呼吸科'];
        Account acc2 = new Account();
        acc2.Name = 'Test2 戦略科室分類 呼吸科';
        acc2.RecordTypeId = rtId2.Id;
        acc2.ParentId = acc1.Id;
        acc2.Department_Class_Label__c = '呼吸科';
        acc2.Hospital_Department_Class__c = acc1.Id;
        insert acc2;
        RecordType rtId3 = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 呼吸科'];
        Account acc3 = new Account();
        acc3.Name = 'Test3 ';
        acc3.RecordTypeId = rtId3.Id;
        acc3.ParentId = acc2.Id;
        acc3.Department_Class__c = acc2.Id;
        acc3.Hospital__c = acc1.Id;
        insert acc3;
        OPDPlan__c opd = new OPDPlan__c();
        opd.Name = 'Test 0330';
        opd.OPDPlan_ImplementDate__c = Date.today();
        opd.Account_Laboratory__c = acc3.Id;
        opd.OPDType__c = '询价';
        opd.NoOpp_Reason__c = 'HCP对应';
        insert opd;
        // Rental_Apply__c rental = TestDataUtility.CreateRentalApplys(1)[0];
        Report__c reportTest = TestDataUtility.CreateReport(1)[0];

        String url = ApexPages.currentPage().getParameters().put('CF00N10000008ps6d_lkid', opd.Id);
        
        Test.startTest();
        Test.setMock(HttpCalloutMock.class, new TestDataUtility.CreateMetaDataUtilityHttpMock());
        ApexPages.StandardController con =  new ApexPages.StandardController(reportTest);
        NewAndEditReportController report = new NewAndEditReportController(con);

        String reportJson = '{"RecordTypeId":"01210000000Qekj","Completed_time_c__c":"2022-03-09 06:18","Hospital_Reference__c":"000000000000000","OwnerId":"0051m0000030e0Q","Department_Class_Ref__c":"000000000000000","Status__c":"草案中","Hospital_Department__c":"0011000000VATK6","Daily_Report__c":"000000000000000","Reporter_State__c":"","Report_OPDPlan__c":"000000000000000","Loaner_request_no1__c":"000000000000000","Date__c":"2022/03/28","Practitioner1__c":"0031m00000N7NSxAAN","Practitioner1_Part__c":"","Practitioner2__c":"000000000000000","Practitioner2_Part__c":"","Practitioner5_others_c__c":"","Purpose1__c":"","Opportunity_Situation__c":"引合発生","Opportunity1__c":"000000000000000","Reason__c":"","Opportunity2__c":"000000000000000","Appeal_Point__c":"","Strategic_Department_Class__c":"","Operation_From__c":null,"Operation_To__c":"","Technical_Category_Manual_c__c":"","Patient_Status__c":"","Operation_Process__c":"","Operation_Task__c":"","Product_Evaluation_Advantage__c":"","Product_Evaluation_Faults__c":"","OPD_Summarize__c":"","Activity_Plan__c":"","OPD_ProductCategory1__c":"","OPD_ProductCategory2__c":"","Product1__c":"000000000000000","OLY_Provide_1__c":"","Product2__c":"000000000000000","OLY_Provide_2__c":"","Product3__c":"000000000000000","OLY_Provide_3__c":"","Product4__c":"000000000000000","OLY_Provide_4__c":"","Product5__c":"000000000000000","OLY_Provide_5__c":"","Evaluation_PDF_number__c":"","Customer_sigh_day_c__c":"","Professor_sigh_text__c":"","Technical_Category1__c":"","Technical_Category2__c":"","Purpose2__c":"引合発生","Customer_sigh_photo__c":""}';
        NewAndEditReportController.saveReport(reportJson,'avgwshDFcxAS',False);
        NewAndEditReportController.saveReport(reportJson,'avgwshDFcxAS',True);
        Test.stopTest();
    }
    static testMethod void testMethod2() {        
        String recordTypeId = Schema.SObjectType.Report__c.getRecordTypeInfosByDeveloperName().get('On_Call').getRecordTypeId();
        Test.setMock(HttpCalloutMock.class, new TestDataUtility.CreateMetaDataUtilityHttpMock());
        String url = ApexPages.currentPage().getParameters().put('00N10000002GE3Z','经销商A');
        url = ApexPages.currentPage().getParameters().put('RecordType',recordTypeId);

        Test.startTest();
        ApexPages.StandardController con =  new ApexPages.StandardController(new Report__c());
        NewAndEditReportController report = new NewAndEditReportController(con);

        Test.stopTest();
    }
    static testMethod void testMethod3() {
        Test.setMock(HttpCalloutMock.class, new TestDataUtility.CreateMetaDataUtilityHttpMock());
        Report__c reportTest = new Report__c();
        Contact cons = TestDataUtility.CreateContacts(1)[0];
        cons.AWS_Data_Id__c = 'test';
        system.debug('cons:' + cons);
        update cons;
        reportTest.Practitioner1__c = cons.ID;
        reportTest.Practitioner2__c = cons.ID;
        reportTest.Practitioner3__c = cons.ID;
        reportTest.Practitioner4__c = cons.ID;
        reportTest.Practitioner5__c = cons.ID;
        reportTest.Person_In_Charge__c = cons.ID;
        reportTest.Manual_Name__c = 'test';
        insert reportTest;
        
        Test.startTest();
        ApexPages.StandardController con =  new ApexPages.StandardController(reportTest);
        NewAndEditReportController report = new NewAndEditReportController(con);
        
        String reportJson = '{"RecordTypeId":"01210000000Qekj","Hospital_Reference__c":"000000000000000","OwnerId":"0051m0000030e0Q","Department_Class_Ref__c":"000000000000000","Status__c":"草案中","Hospital_Department__c":"0011000000VATK6","Daily_Report__c":"000000000000000","Reporter_State__c":"","Engineer__c":null,"Report_OPDPlan__c":"000000000000000","Loaner_request_no1__c":"000000000000000","Date__c":"2022/03/28","Inspection_start_time__c":"2022-03-09T06:18:16.000+0000","Thermal_Diffusion_Worry__c":"false","Practitioner1__c":"0031m00000N7NSxAAN","Practitioner1_Part__c":"","Practitioner2__c":"000000000000000","Practitioner2_Part__c":"","Practitioner5_others_c__c":"","Purpose1__c":"","Opportunity_Situation__c":"引合発生","Opportunity1__c":"000000000000000","Reason__c":"","Opportunity2__c":"000000000000000","Appeal_Point__c":"","Dean_Of_Maintenance__c":"null","Strategic_Department_Class__c":"","Operation_From__c":"2022-02-15T00:41:16.000+0000","Operation_To__c":"","Technical_Category_Manual_c__c":"","Patient_Status__c":"","Operation_Process__c":"","Operation_Task__c":"","Product_Evaluation_Advantage__c":"","Product_Evaluation_Faults__c":"","OPD_Summarize__c":"","Activity_Plan__c":"","OPD_ProductCategory1__c":"","OPD_ProductCategory2__c":"","Product1__c":"000000000000000","OLY_Provide_1__c":"","Product2__c":"000000000000000","OLY_Provide_2__c":"","Product3__c":"000000000000000","OLY_Provide_3__c":"","Product4__c":"000000000000000","OLY_Provide_4__c":"","Product5__c":"000000000000000","OLY_Provide_5__c":"","Evaluation_PDF_number__c":"","Customer_sigh_day_c__c":"","Professor_sigh_text__c":"","Technical_Category1__c":"","Technical_Category2__c":"","Purpose2__c":"引合発生","Customer_sigh_photo__c":""}';
        NewAndEditReportController.saveReport(reportJson,'avgwshDFcxAS',False);
        NewAndEditReportController.saveReport(reportJson,'avgwshDFcxAS',True);
        Test.stopTest();
    }
}