@isTest
private class MeetingDelayApplyTriggerTest {


    static testMethod void testMethod1() {
        RecordType rectCam =
	    [select Id from RecordType
	     where IsActive = true and SobjectType = 'Campaign'
	                      and DeveloperName = 'ServiceEngineerTraining'];

		Campaign cam = new Campaign();
		cam.Name = 'camTest';
		cam.Name2__c = '1234Test';
		cam.RecordTypeId = rectCam.Id;
		cam.StartDate = Date.today().addDays(-15);
		cam.EndDate = Date.today().addDays(18);
		cam.Mailflg_after45__c = true;
		cam.Mailflg_cancel__c = true;
		cam.Mailflg_before15__c = true;
		cam.Mailflg_before7__c = true;
		cam.Mailflg_after3__c = true;
		cam.Status = '申请中';
		insert cam;

        //需要一个meetings 的对象集合
        meeting_delay_apply__c m = new meeting_delay_apply__c();
        m.Meeting_Type__c = '共同主办会';
        m.HostName__c = '主办方Test';
        m.cooperatorCompany__c = '承办方Test';
        m.status__c = '草案中';
        m.campaign__c = cam.Id;
        insert m;


        m.status__c = '审批中';
        update m;

        m.status__c = '已完成';
        update m;

		String meetingDealyRecordId = Schema.SObjectType.meeting_delay_apply__c.getRecordTypeInfosByDeveloperName().get('MeetingPostpone').getRecordTypeId();
		String meetingCancleRecordId = Schema.SObjectType.meeting_delay_apply__c.getRecordTypeInfosByDeveloperName().get('CancelApplication').getRecordTypeId();
		meeting_delay_apply__c m1 = new meeting_delay_apply__c();
        m1.Meeting_Type__c = '共同主办会';
        m1.HostName__c = '主办方Test';
        m1.cooperatorCompany__c = '承办方Test';
        m1.status__c = '草案中';
        m1.campaign__c = cam.Id;
		m1.RecordTypeId = meetingDealyRecordId;
        insert m1;


        m1.status__c = '审批中';
        update m1;

        m1.status__c = '已完成';
        update m1;

		meeting_delay_apply__c m2 = new meeting_delay_apply__c();
        m2.Meeting_Type__c = '共同主办会';
        m2.HostName__c = '主办方Test';
        m2.cooperatorCompany__c = '承办方Test';
        m2.status__c = '草案中';
        m2.campaign__c = cam.Id;
		m2.RecordTypeId = meetingCancleRecordId;
        insert m2;


        m2.status__c = '审批中';
        update m2;

        m2.status__c = '已完成';
        update m2;

        Campaign camp = [
				            SELECT Id ,StartDate ,EndDate ,
				            PlanBackData__c ,Meeting_Type__c ,HostName__c ,cooperatorCompany__c , 
				            Meeting_Cooperate__c ,Meeting_Cooperate2__c ,Meeting_Cooperate3__c ,Meeting_Cooperate4__c 
				            FROM Campaign WHERE Id = : m.campaign__c
				        ];
		System.debug('审批节点走到 `已完成` 后cam的值:  预计: hostname= 主办方test,cooperatorCompany__c = 承办方Test 实际值为: '+camp);
        
    }

    static testMethod void testMethod2() {

	  	RecordType rectCam =
	    [select Id from RecordType
	     where IsActive = true and SobjectType = 'Campaign'
	                      and DeveloperName = 'ServiceEngineerTraining'];

		Campaign cam = new Campaign();
		cam.Name = 'cam';
		cam.Name2__c = '1234';
		cam.RecordTypeId = rectCam.Id;
		cam.StartDate = Date.today().addDays(-15);
		cam.EndDate = Date.today().addDays(18);
		cam.Mailflg_after45__c = true;
		cam.Mailflg_cancel__c = true;
		cam.Mailflg_before15__c = true;
		cam.Mailflg_before7__c = true;
		cam.Mailflg_after3__c = true;
		cam.Status = '公开中';
		insert cam;

        //需要一个meetings 的对象集合
        meeting_delay_apply__c m = new meeting_delay_apply__c();
        m.Meeting_Type__c = '主办会';
        m.HostName__c = '主办方3';
        m.cooperatorCompany__c = '承办方3';
        m.status__c = '草案中';
        m.campaign__c = cam.Id;
        insert m;

        System.runAs(new User(Id = UserInfo.getUserId())){
        	m.status__c = '审批中';
	        update m;

	        m.status__c = '已完成';
	        update m;
        }

        Campaign camp = [
				            SELECT Id ,StartDate ,EndDate ,
				            PlanBackData__c ,Meeting_Type__c ,HostName__c ,cooperatorCompany__c , 
				            Meeting_Cooperate__c ,Meeting_Cooperate2__c ,Meeting_Cooperate3__c ,Meeting_Cooperate4__c 
				            FROM Campaign WHERE Id = : m.campaign__c
				        ];
		System.debug('审批节点走到 `已完成` 后cam的值:  预计: hostname= 主办方test,cooperatorCompany__c = 承办方Test 实际值为: '+camp);
        
    }

    static testMethod void testMethod3() {
  		RecordType rectCam =
	    [select Id from RecordType
	     where IsActive = true and SobjectType = 'Campaign'
	                      and DeveloperName = 'ServiceEngineerTraining'];

		Campaign cam = new Campaign();
		cam.Name = 'cam';
		cam.Name2__c = '1234';
		cam.RecordTypeId = rectCam.Id;
		cam.StartDate = Date.today().addDays(-15);
		cam.EndDate = Date.today().addDays(18);
		cam.Mailflg_after45__c = true;
		cam.Mailflg_cancel__c = true;
		cam.Mailflg_before15__c = true;
		cam.Mailflg_before7__c = true;
		cam.Mailflg_after3__c = true;
		insert cam;

        //需要一个meetings 的对象集合
        meeting_delay_apply__c m = new meeting_delay_apply__c();
        m.Meeting_Type__c = '赞助会';
        m.HostName__c = '主办方3';
        m.cooperatorCompany__c = '承办方3';
        m.status__c = '草案中';
        m.campaign__c = cam.Id;
        insert m;


       	m.status__c = '审批中';
        update m;

        m.status__c = '驳回';
        update m;

        Campaign camp = [
		            SELECT Id ,StartDate ,EndDate ,
		            PlanBackData__c ,Meeting_Type__c ,HostName__c ,cooperatorCompany__c , 
		            Meeting_Cooperate__c ,Meeting_Cooperate2__c ,Meeting_Cooperate3__c ,Meeting_Cooperate4__c 
		            FROM Campaign WHERE Id = : m.campaign__c
		        ];
        
    }

}