高章伟
2023-03-03 d8dc84a3d56df839895f1c417a4d9cbee763d262
force-app/main/default/classes/SyncAccountContactToAWSTest.cls
@@ -1,5 +1,15 @@
@isTest
public class SyncAccountContactToAWSTest {
    @Testsetup
    static void setup(){
        List<String> strList = new List<String>();
        strList.add('Agency_Contact__c');
        strList.add('Agency_Contact__cV2');
        strList.add('Contact');
        TestDataUtility.CreatePIPolicyConfigurations(strList);
    }
   class HttpMock implements HttpCalloutMock{
        
        public HTTPResponse respond(HTTPRequest request) {
@@ -15,11 +25,11 @@
                } else if(request.getEndpoint().contains('insert')){
                    system.debug('url=Insert');
                    response.setHeader('Content-Type', 'application/json');
            body='{ "message": "", "object": [ { "dataId": "123456", "directShippmentAddress": "", "directShippmentAddressEncrypt": "", "isDelete": 0, "phoneNumber": "", "phoneNumberEncrypt": "", "sfRecordId": "a2R1m0000007BPD" } ], "status": "", "success": true, "timestamp": 0, "txId": "" }';
            body='{ "message": "", "object": { "dataId": "123456", "directShippmentAddress": "", "directShippmentAddressEncrypt": "", "isDelete": 0, "phoneNumber": "", "phoneNumberEncrypt": "", "sfRecordId": "a2R1m0000007BPD" }, "status": "", "success": true, "timestamp": 0, "txId": "" }';
                } else if(request.getEndpoint().contains('update')){
                    system.debug('url=update');
                    response.setHeader('Content-Type', 'application/json');
            body='{ "message": "", "object": [ { "dataId": "123456", "directShippmentAddress": "", "directShippmentAddressEncrypt": "", "isDelete": 0, "phoneNumber": "", "phoneNumberEncrypt": "", "sfRecordId": "a2R1m0000007BPD" } ], "status": "", "success": true, "timestamp": 0, "txId": "" }';
            body='{ "message": "", "object": { "dataId": "123456", "directShippmentAddress": "", "directShippmentAddressEncrypt": "", "isDelete": 0, "phoneNumber": "", "phoneNumberEncrypt": "", "sfRecordId": "a2R1m0000007BPD" }, "status": "", "success": true, "timestamp": 0, "txId": "" }';
                } else{}
        
        response.setBody(body);
@@ -31,22 +41,27 @@
    }
    @isTest
    static void startTest() {
        TestDataUtility.CreatePIPolicyConfigurations(new string[]{'Agency_Contact__c','Contact'});
        Test.setMock(HttpCalloutMock.class, new HttpMock());
        List<Contact> conList = TestDataUtility.CreateContacts(1);
        List<Agency_Contact__c> lra = new List<Agency_Contact__c>();
        lra.add(new Agency_Contact__c(AWS_Data_Id__c='Test AWS'));
        lra.add(new Agency_Contact__c(AWS_Data_Id__c='Test AWS',Contact__c=conList[0].Id));
        insert lra;
        System.Test.startTest();
        try{
            //String soql = 'SELECT id,Doctor_Division1__c,Doctor_Division1_Encrypted__c,Name,Name_Encrypted__c,Type__c,Type_Encrypted__c,AWS_Data_Id__c,Contact__c, Contact__r.Doctor_Division1_Encrypted__c,Contact__r.LastName_Encrypted__c, Contact__r.Type_Encrypted__c FROM Agency_Contact__c WHERE id=\'a2R10000001cfatEAA\' And AWS_Data_Id__c =\'\' And Contact__c != null';
            String soql = 'SELECT id,Doctor_Division1__c,Doctor_Division1_Encrypted__c,Name,Name_Encrypted__c,Type__c,Type_Encrypted__c,AWS_Data_Id__c,Contact__c, Contact__r.Doctor_Division1_Encrypted__c,Contact__r.LastName_Encrypted__c, Contact__r.Type_Encrypted__c FROM Agency_Contact__c WHERE AWS_Data_Id__c =\'Test AWS\'';
            SyncAccountContactToAWS contactBatch = new SyncAccountContactToAWS(soql);
            List<Agency_Contact__c> acList = Database.query(soql) ;
            Map<Id,Contact> ContactMap = new Map<Id,Contact>();
            ContactMap.put(conList[0].Id,conList[0]);
            SyncAccountContactToAWS contactBatch = new SyncAccountContactToAWS(soql,ContactMap);
            SyncAccountContactToAWS contactBatchTest = new SyncAccountContactToAWS();
            Id execBTId = Database.executeBatch(contactBatch,1);
        }catch(Exception e){
            system.debug('Exception from sync aws batch:'+ e.getMessage());
        }
        try{
            SyncAccountContactToAWS.assignOnceOneMinuteLater();
            SyncAccountContactToAWS.assignOnceOneMinuteLater(new List<Agency_Contact__c>(),new Map<Id,Contact>());
        }catch(Exception e){
            system.debug('Exception from sync aws scheduler:'+ e.getMessage());
        }