/*
 * Author: Guo, Aline Yaying
 * Created Date: 03/22/2022
 * Purpose: Test Class
 * History: 
 *      03/22/2022 - Guo, Aline Yaying - Initial Code.
 * 
 * */
@isTest
private class NewAndEditBaseControllerTest {
    static testMethod void testMethod1() {
     
        RecordType rtId = [select Id, SobjectType, Name from RecordType where SobjectType = 'Tender_information__c' and Name = '千里马'];
        TestDataUtility.CreatePIPolicyConfiguration();
        Test.setMock(HttpCalloutMock.class, new TestDataUtility.CreateMetaDataUtilityHttpMock());
        //use a random sobj
        Tender_information__c tenTest = TestDataUtility.CreateTenderInformation(1)[0];
        tenTest.ResultDate__c = null;
        tenTest.InfoPublishTime__c = Datetime.now();
        tenTest.OpportunityNum__c = null;
        tenTest.Other_units__c = false;
        tenTest.AWS_Data_Id__c = '1569989';
        tenTest.RecordTypeId = rtId.Id;
        upsert tenTest;

        Test.startTest();
        //ApexPages.StandardController con =  new ApexPages.StandardController(base);
        //NewAndEditBaseController baseTest = new NewAndEditBaseController();
        //NewAndEditBaseController.Init(base);
        ApexPages.StandardController con =  new ApexPages.StandardController(tenTest);
        NewAndEditTenderinformationController a = new NewAndEditTenderinformationController(con);
        a.Init(tenTest);
        String AWSjson = a.AWSToSobjectMapJson;
        NewAndEditBaseController.GetReferenceField('test__c');
        NewAndEditBaseController.GetReferenceField('Id');
        NewAndEditBaseController.GetReferenceField('t');
        
        System.debug('tenTest' + tenTest);
        String baseJson = JSON.serialize(tenTest);
        System.debug('baseJson' + baseJson);
        NewAndEditBaseController.save(tenTest, baseJson, 'avgwshDFcxAS', false);
        Test.stopTest();
    }

    static testMethod void testMethod2() {
     
        List<String> LookUpOverrideFields = new List<String>();
        TestDataUtility.CreatePIPolicyConfiguration();
        Test.setMock(HttpCalloutMock.class, new TestDataUtility.CreateMetaDataUtilityHttpMock());
        //use a random sobj
        ASEActivity__c aseTest = TestDataUtility.CreateASEActivity(1)[0];
        aseTest.activityStartTime__c = null;
        upsert aseTest;

        Test.startTest();
        //ApexPages.StandardController con =  new ApexPages.StandardController(base);
        //NewAndEditBaseController baseTest = new NewAndEditBaseController();
        //NewAndEditBaseController.Init(base);
        ApexPages.StandardController con =  new ApexPages.StandardController(aseTest);
        NewAndEditASEActivityController a = new NewAndEditASEActivityController(con);
        LookUpOverrideFields.add('ReporterASE__c');
        a.Init(aseTest);
        String AWSjson = a.AWSToSobjectMapJson;
        aseTest.put('AWS_Data_Id__c','1569989');
        String baseJson = JSON.serialize(aseTest);
        System.debug('baseJson' + baseJson);

        NewAndEditBaseController.save(aseTest, baseJson, 'avgwshDFcxAS', true);
        NewAndEditBaseController.save(aseTest, baseJson, 'avgwshDFcxAS', null);
        Test.stopTest();
    }

    static testMethod void testMethod3() {
     
        List<String> LookUpOverrideFields = new List<String>();
        TestDataUtility.CreatePIPolicyConfiguration();
        Test.setMock(HttpCalloutMock.class, new TestDataUtility.CreateMetaDataUtilityHttpMock());
        //use a random sobj
        Contact contact = TestDataUtility.CreateContacts(1)[0];
        ASEActivity__c aseTest = new ASEActivity__c();
        aseTest.CustomerTel__c = '123123';
        aseTest.ReporterASE__c = contact.Id;
        aseTest.activityStartTime__c = null;

        Test.startTest();
        //ApexPages.StandardController con =  new ApexPages.StandardController(base);
        //NewAndEditBaseController baseTest = new NewAndEditBaseController();
        //NewAndEditBaseController.Init(base);
        ApexPages.StandardController con =  new ApexPages.StandardController(aseTest);
        NewAndEditASEActivityController a = new NewAndEditASEActivityController(con);
        LookUpOverrideFields.add('ReporterASE__c');
        a.Init(aseTest);
        String AWSjson = a.AWSToSobjectMapJson;
        aseTest.put('AWS_Data_Id__c','1569989');        
        String baseJson = JSON.serialize(aseTest);
        System.debug('baseJson' + baseJson);
        NewAndEditBaseController.save(aseTest, baseJson, 'avgwshDFcxAS', true);
        Test.stopTest();
    }
}