/*
 * Author: Guo, Aline Yaying
 * Created Date: 03/22/2022
 * Purpose: Test Class
 * History: 
 *      03/22/2022 - Guo, Aline Yaying - Initial Code.
 * 
 * */
@isTest
private class NewAndEditAddressControllerTest {
    static testMethod void testMethod1() {
     
        TestDataUtility.CreatePIPolicyConfiguration();
        Test.setMock(HttpCalloutMock.class, new TestDataUtility.CreateMetaDataUtilityHttpMock());
        Address__c ad = TestDataUtility.CreateAddresses(1)[0];

        Test.startTest();
        ad.Using_Datetime__c = null;
        ApexPages.StandardController con =  new ApexPages.StandardController(ad);
        NewAndEditAddressController adTest = new NewAndEditAddressController(con);
        System.debug('adTest----'+adTest);
        Map<String,Object> mapTest = new Map<String,Object>();
        mapTest.put('Contacts__c',ad.Contacts__c);
        mapTest.put('Using_Datetime__c',ad.Using_Datetime__c);
        mapTest.put('Customer__c',ad.Customer__c);
        mapTest.put('Telephone__c',ad.Telephone__c);
        mapTest.put('Province__c',ad.Province__c);
        mapTest.put('City__c',ad.City__c);
        mapTest.put('Detailed_Address__c',ad.Detailed_Address__c);
        mapTest.put('Address_Classification__c',ad.Address_Classification__c);
        String addressJson = JSON.serialize(mapTest);
  
        NewAndEditAddressController.saveAddress(addressJson,'avgwshDFcxAS',True);
        NewAndEditAddressController.saveAddress(addressJson,'avgwshDFcxAS',False);
        Test.stopTest();
    }

    static testMethod void testMethod2() {
     
        TestDataUtility.CreatePIPolicyConfiguration();
        Test.setMock(HttpCalloutMock.class, new TestDataUtility.CreateMetaDataUtilityHttpMock());
        Address__c ad2 = TestDataUtility.CreateAddresses(1)[0];
        ad2.Using_Datetime__c = Datetime.now();
        ad2.IsFromSPO__c = false;
        insert ad2;

        Test.startTest();
        System.debug('ad2' + ad2);
        ApexPages.StandardController con =  new ApexPages.StandardController(ad2);
        System.debug('con.Id' + con.getRecord().Id);
        NewAndEditAddressController adTest = new NewAndEditAddressController(con);
        System.debug('adTest----'+adTest);
        Map<String,Object> mapTest = new Map<String,Object>();
        mapTest.put('Contacts__c',ad2.Contacts__c);
        mapTest.put('Using_Datetime__c',ad2.Using_Datetime__c);
        mapTest.put('Customer__c',ad2.Customer__c);
        mapTest.put('Telephone__c',ad2.Telephone__c);
        mapTest.put('Province__c',ad2.Province__c);
        mapTest.put('City__c',ad2.City__c);
        mapTest.put('Detailed_Address__c',ad2.Detailed_Address__c);
        mapTest.put('Address_Classification__c',ad2.Address_Classification__c);
        mapTest.put('IsFromSPO__c',ad2.IsFromSPO__c);
        String addressJson = JSON.serialize(mapTest);
        System.debug('addressJson:' + addressJson);

        NewAndEditAddressController.saveAddress(addressJson,'avgwshDFcxAS',False);
        Test.stopTest();
    }
}