@isTest
private class Send_Have_Arrival_wh_Email_Batch_Test {
    static ReceivingNoteTestDataFactory factory;
    /**
    @description 安装master数据
    */
    @testSetup static void setupMasterData(){
        factory = new ReceivingNoteTestDataFactory();
        factory.setupMasterData();
    }
    /**
    @param typeStringListString 格式：'备品类型,管理种类;备品类型,管理种类...'
    @description 造出指定类型的清单数据,并插入数据库
    */
    static void setupTestData(String typeStringListString){
        factory = new ReceivingNoteTestDataFactory();
        if(String.isBlank(typeStringListString)){
            typeStringListString = '固定资产,个体管理;附属品,个体管理;附属品,数量管理;耗材,数量管理;低值易耗品,数量管理';
        }
        List<String> typeStringList = typeStringListString.split(';');
        factory.setupReceivingNoteData(typeStringList);
    }
    /**
    @description 测试邮件batch
    */
    static testMethod void testEmailBatch() {
        // 造出已入库的数据
        // 状态调整为已入库指示
        setupTestData('固定资产,个体管理');
        ReceivingNoteSummary__c  rns = factory.rnsMap.get('固定资产,个体管理');
        rns.Received_Confirm_Time__c = System.Now();
        upsert rns Internal_Asset_number__c;
        ReceivingNoteDetail__c rnd = factory.rndMap.get('固定资产,个体管理');
        rnd.unknow_serial_NO_product__c = 'TRUE';
        rnd.Loaner_accsessary__c = 'TRUE';
        //rnd.DataConfirmation__c = true;
        rnd.AcceptanceTime__c = System.Now();
        rnd.AcceptanceResult__c = 'OK';
        rnd.Inspection_result_after__c = 'OK';
        rnd.DataConfirmationAgain__c = true;
        rnd.Arrival_wh_Request_time__c = System.Now();
        rnd.Arrival_in_wh__c = true;

        ReceivingNoteDetail__c rnd1 = new ReceivingNoteDetail__c();
        rnd1.ReceivingNoteSummary__c = rns.Id;
        rnd1.Fixture_Set_Detail__c = factory.fsdList[1].Id;
        rnd1.Product_Serial_No__c = 'SB-PRO-SERIAL-x';
        rnd1.passNo2__c = '02';
        rnd1.passNo3__c = '1';
        rnd1.Arrival_wh_Request_time__c = System.Now();
        rnd1.Arrival_in_wh__c = true;

        ReceivingNoteDetail__c rnd2 = new ReceivingNoteDetail__c();
        rnd2.ReceivingNoteSummary__c = rns.Id;
        rnd2.Fixture_Set_Detail__c = factory.fsdList[1].Id;
        rnd2.Product_Serial_No__c = 'SB-PRO-SERIAL-y';
        rnd2.passNo2__c = '02';
        rnd2.passNo3__c = '2';
        rnd2.Arrival_wh_Request_time__c = System.Now();
        rnd2.Arrival_in_wh__c = true;

        upsert new List<ReceivingNoteDetail__c> {rnd,rnd1,rnd2} Product_Serial_No__c;

        ReceivingNote__c rn = [SELECT Have_Arrival_wh_Email__c FROM ReceivingNote__c];
        System.assertEquals(null, rn.Have_Arrival_wh_Email__c);

        Test.startTest();
        Send_Have_Arrival_wh_Email_BatchSchedul emailSend_Have_Arrival_wh_Email_BatchSchedul = new Send_Have_Arrival_wh_Email_BatchSchedul();
        SchedulableContext sc;
        emailSend_Have_Arrival_wh_Email_BatchSchedul.execute(sc);
        Test.stopTest();

        rn = [SELECT Have_Arrival_wh_Email__c FROM ReceivingNote__c];
        System.assertEquals('SB-MODEL-01 SB-MODEL-02 * 2', rn.Have_Arrival_wh_Email__c);
    }
}