/*
 * Created Date: 07/05/2022
 * Purpose: Test Class
 * History: 
 *      07/05/2022 -  Yanan Chen - Initial Code.
 * 
 * */
@isTest
public class NewAndEditAgencyOppoControllerTest {
    public static Account account1 = new Account();
    public static Account account2 = new Account();
    public static Agency_Hospital_Link__c aHosLink = new Agency_Hospital_Link__c();
    public static Agency_Contact__c aContact = new Agency_Contact__c();
    static testMethod void testMethod1() {
        Oly_TriggerHandler.bypass('AgencyReportHeaderHandler');
        Oly_TriggerHandler.bypass('AgencyHospitalHandler');
        StaticParameter.EscapeAccountTrigger = true;
        StaticParameter.EscapeNFM007Trigger = true;
        StaticParameter.EscapeOpportunityBefUpdTrigger = true;
        StaticParameter.EscapeOpportunityHpDeptUpdTrigger = true;
        StaticParameter.EscapeSyncOpportunityTrigger = true;
        StaticParameter.EventOpportunityPileUpExeFlg = true;
        StaticParameter.EscapeNFM001AgencyContractTrigger = true;
        StaticParameter.EscapeNFM001AgencyContractTrigger2 = true;
        StaticParameter.EscapeLeadTrigger = true;
        StaticParameter.EscapeOpportunityownerUpdate = true;
        ControllerUtil.EscapeNFM001Trigger = true;
        ControllerUtil.EscapeMaintenanceContractAfterUpdateTrigger = true;
        StaticParameter.EscapeNFM001Trigger = true;
        StaticParameter.EscapeMaintenanceContractAfterUpdateTrigger = true;
        TestDataUtility.CreatePIPolicyConfiguration();
        Test.setMock(HttpCalloutMock.class, new TestDataUtility.CreateMetaDataUtilityHttpMock());

        Profile p = [select Id from Profile where Name = '901_经销商活动系统'];
        System.debug(p.Id);
        User user = [select Id from User where ProfileId =: p.Id];      
        System.debug('user: ' + user.Id); 

        account1.Name = 'test1医院';
        account1.RecordTypeId = '01210000000QemG';
        insert account1;

        account2.Name = 'test1经销商';
        account2.RecordTypeId = '01210000000Qem1';
        insert account2;

        //经销商医院データを作る
        aHosLink.Name = 'test1经销商医院';
        aHosLink.Hospital__c = account1.Id;
        aHosLink.Agency__c = account2.Id;
        aHosLink.Agency_Campaign_Obj__c = true;
        aHosLink.OwnerId = user.Id;
        insert aHosLink;

        Agency_Contact__c aContact1 = new Agency_Contact__c();
        aContact1.Agency_Hospital__c = aHosLink.Id;
        aContact1.Type__c = '医生';
        aContact1.AWS_Data_Id__c = '1234567890';
        aContact1.Name = 'testAgencyUser';

        Test.startTest();
        insert aContact1;

        Agency_Opportunity__c agencyOpportunity = new Agency_Opportunity__c();
        agencyOpportunity.RecordTypeId = Schema.SObjectType.Agency_Opportunity__c.getRecordTypeInfosByDeveloperName().get('Opportunity').getRecordTypeId();
        agencyOpportunity.Name = '引合2';
        agencyOpportunity.Agency_Hospital__c = aHosLink.Id;
        agencyOpportunity.Agency_Contact__c = aContact1.Id;
        agencyOpportunity.StageName__c = '还没申请预算';
        agencyOpportunity.NewOpportunity_Agency_Apply_Status__c = '批准';
        insert agencyOpportunity;

        ApexPages.StandardController con =  new ApexPages.StandardController(agencyOpportunity);
        NewAndEditAgencyOpportunityController ao = new NewAndEditAgencyOpportunityController(con);
        
        Test.stopTest();
    }
}