@isTest
public with sharing class Batch_FixnoteToFilesTest {
    @isTest
    static void testInit() {
        String rectCo = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Agency').getRecordTypeId();
        Account accountItem1 = new Account(Name='Testaccount001',RecordTypeId = rectCo);
        insert accountItem1;

        Consumable_order__c consOrder = new Consumable_order__c();
        consOrder.Name = 'test01';
        consOrder.Order_status__c = '批准';
        consOrder.Deliver_date__c = Date.today();
        consOrder.RecordTypeid = System.Label.RT_ConOrder_Delivery;
        consOrder.Order_type__c = '订单';
        consOrder.Order_ProType__c = 'ENG';
        consOrder.Dealer_Info__c = accountItem1.Id;
        consOrder.Delivery_detail_count__c = 5;
        insert consOrder;
        Oly_TriggerHandler.bypass('NotetoPdfHandler');
        List<Note> attachList = new List<Note>();
        Note attach = new Note();
        attach.Title='A-65224941-20200923--1.docx';
        //Blob bodyBlob= Blob.valueOf('Unit Test Attachment Body');
        //attach.body = bodyBlob;
        attach.ParentId = consOrder.Id;
        attachList.add(attach);
        insert attachList;
        
        Set<String> Id = new Set<String>();
        String objectType;
        Datetime creStartDate;
        Datetime creEndDate;
        
        List<Note> attachmentList = [Select Id, Title, OwnerId, ParentId, Parent.Name, Parent.Type, Body, CreatedDate, CreatedById 
                                             From Note 
                                            Where Id =:attachList[0].Id 
                                            Order by CreatedDate ASC 
                                            Limit 1];
        for (Note att : attachmentList) {
            Id.add(att.ParentId);
            objectType = att.Parent.Name;
            creStartDate = att.CreatedDate;
            creEndDate = att.CreatedDate.addDays(1);
        }
        System.Test.startTest();
        Database.executeBatch(new Batch_FixnoteToFiles(objectType,creStartDate,creEndDate),1);
        Database.executeBatch(new Batch_FixnoteToFiles(Id),1);
        System.Test.stopTest(); 
    }
}