/*
 * Author: Guo, Aline Yaying
 * Created Date: 03/22/2022
 * Purpose: Test Class
 * History: 
 *      03/22/2022 - Guo, Aline Yaying - Initial Code.
 * 
 * */
@isTest
private class NewAndEditInquiryFormControllerTest {
    static testMethod void testMethod5() {
    
        TestDataUtility.CreatePIPolicyConfiguration();
        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;
        Contact contact = TestDataUtility.CreateContacts(1)[0];
        contact.AccountId = acc3.Id;
        upsert contact;
        Inquiry_form__c formTest = TestDataUtility.CreateInquiryform(1)[0];
        formTest.AWS_Data_Id__c = '165';
        formTest.Hospital__c = acc1.Id;
        formTest.Department_Class__c = acc2.Id;
        formTest.Hospital_Name__c = acc3.Id;
        formTest.Contact_Name__c = contact.Id;
        System.debug('formTest: ' + formTest);
        upsert formTest;
        String url = ApexPages.currentPage().getParameters().put('CF00N1000000962n8_lkid',contact.id);
        
        Test.startTest();
        ApexPages.StandardController con =  new ApexPages.StandardController(formTest);
        NewAndEditInquiryFormController form = new NewAndEditInquiryFormController(con);
        String formJson = '{"Id": "a410l00000067xyAAA","AWS_Data_Id__c": "952951318358523905","Lead_link__c": null,"Hospital__c": null,"Contact_Name__c": "0030l00000mEx8UAAS","No_Need_Date__c": null,"Urgent__c": false}';
        System.debug('formJson: ' + formJson);
        NewAndEditInquiryFormController.saveInquiryForm(formJson,'avgwshDFcxAS',False);
        String jsonString = '["Department_Class__c", "Hospital__c"]';
        NewAndEditInquiryFormController.queryAccount(jsonString, contact.AccountId);
        Test.stopTest();
    }

    static testMethod void testMethod1() {
    
        TestDataUtility.CreatePIPolicyConfiguration();
        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;
        Contact contact = TestDataUtility.CreateContacts(1)[0];
        contact.AccountId = acc3.Id;
        contact.AWS_Data_Id__c = '167895';
        upsert contact;
        Inquiry_form__c formTest = TestDataUtility.CreateInquiryform(1)[0];
        formTest.AWS_Data_Id__c = '165';
        formTest.Hospital__c = acc1.Id;
        formTest.Department_Class__c = acc2.Id;
        formTest.Hospital_Name__c = acc3.Id;
        formTest.Contact_Name__c = contact.Id;
        System.debug('formTest: ' + formTest);
        upsert formTest;
        
        Test.startTest();
        ApexPages.StandardController con =  new ApexPages.StandardController(formTest);
        NewAndEditInquiryFormController form = new NewAndEditInquiryFormController(con);
        String formJson = '{"Id": "a410l00000067xyAAA","AWS_Data_Id__c": "952951318358523905","Lead_link__c": null,"Hospital__c": null,"Contact_Name__c": "0030l00000mEx8UAAS","No_Need_Date__c": null,"Urgent__c": false}';
        System.debug('formJson: ' + formJson);
        NewAndEditInquiryFormController.saveInquiryForm(formJson,'avgwshDFcxAS',False);
        Test.stopTest();
    }

    static testMethod void testMethod2() {
    
        TestDataUtility.CreatePIPolicyConfiguration();
        Test.setMock(HttpCalloutMock.class, new TestDataUtility.CreateMetaDataUtilityHttpMock());
        Account acc = TestDataUtility.CreateAccounts(1)[0];
        Inquiry_form__c formTest = TestDataUtility.CreateInquiryform(1)[0];
        formTest.Contact_Name__c = null;
        upsert formTest;
        
        Test.startTest();
        ApexPages.StandardController con =  new ApexPages.StandardController(formTest);
        NewAndEditInquiryFormController form = new NewAndEditInquiryFormController(con);
        String formJson = '{"Id": "a410l00000067xyAAA","AWS_Data_Id__c": "952951318358523905","Lead_link__c": null,"Hospital__c": null,"Contact_Name__c": "0030l00000mEx8UAAS","No_Need_Date__c": null,"Urgent__c": false}';
        System.debug('formJson: ' + formJson);
        NewAndEditInquiryFormController.saveInquiryForm(formJson,'avgwshDFcxAS',False);
        Test.stopTest();
    }

    static testMethod void testMethod3() {
    
        TestDataUtility.CreatePIPolicyConfiguration();
        Test.setMock(HttpCalloutMock.class, new TestDataUtility.CreateMetaDataUtilityHttpMock());
        Account acc = TestDataUtility.CreateAccounts(1)[0];
        Inquiry_form__c formTest = new Inquiry_form__c();
        formTest.Name = 'Test InquiryForm';
        formTest.Request1__c = 'OPD'; 
        formTest.Opportunity_Division__c = '询价'; 
        
        Test.startTest();
        ApexPages.StandardController con =  new ApexPages.StandardController(formTest);
        NewAndEditInquiryFormController form = new NewAndEditInquiryFormController(con);
        String formJson = '{"Id": "a410l00000067xyAAA","AWS_Data_Id__c": "952951318358523905","Lead_link__c": null,"Hospital__c": null,"Contact_Name__c": "0030l00000mEx8UAAS","No_Need_Date__c": null,"Urgent__c": false}';
        System.debug('formJson: ' + formJson);
        NewAndEditInquiryFormController.saveInquiryForm(formJson,'avgwshDFcxAS',False);
        Test.stopTest();
    }
}