@isTest
private class RepairReceiptBatchTest {

	@isTest static void test_method_one() {

		Profile p = [select Id from Profile where id =: System.Label.ProfileId_SystemAdmin];
        User u1 = new User(Test_staff__c = true);
        u1.LastName = '_サンブリッジ';
        u1.FirstName = 'あ';
        u1.Alias = 'あ';
        u1.Email = 'olympusTest01@sunbridge.com';
        u1.Username = 'olympusTest01@sunbridge.com';
        u1.CommunityNickname = 'あ';
        u1.IsActive = true;
        u1.EmailEncodingKey = 'ISO-2022-JP';
        u1.TimeZoneSidKey = 'Asia/Tokyo';
        u1.LocaleSidKey = 'ja_JP';
        u1.LanguageLocaleKey = 'ja';
        u1.ProfileId = p.Id;
        u1.Job_Category__c = '销售服务';
        u1.Province__c = '東京';
        insert u1;

        User u2 = new User(Test_staff__c = true);
        u2.LastName = '_サンブリッジ';
        u2.FirstName = 'い';
        u2.Alias = 'い';
        u2.Email = 'olympusTest02@sunbridge.com';
        u2.Username = 'olympusTest02@sunbridge.com';
        u2.CommunityNickname = 'い';
        u2.IsActive = true;
        u2.EmailEncodingKey = 'ISO-2022-JP';
        u2.TimeZoneSidKey = 'Asia/Tokyo';
        u2.LocaleSidKey = 'ja_JP';
        u2.LanguageLocaleKey = 'ja';
        u2.ProfileId = p.Id;
        u2.Job_Category__c = '销售推广';
        u2.Province__c = '東京';
        insert u2;

		system.runAs(u2) {

        
  
        Date toDate = Date.today();
        Date expirationDate = toDate.toStartOfMonth()-1;
        //system.debug('2222222222_____' + Integer.valueOf(expirationDate));
        Repair_receipt__c rr = new Repair_receipt__c();
        rr.Name = '123456';
        rr.UniqueKey__c = '1234567';
        rr.Repair__c = System.Label.Olympus_Dummy_Repair;
        rr.Maintenance_Contract__c =  System.Label.Olympus_Dummy_MC;
        rr.PaymentAmount__c = Decimal.valueOf('1235');
        //rr.PaymentDate__c = NFMUtil.parseStr2Date('20190422');
        rr.PaymentDate__c = expirationDate;

        rr.DeadlineLastMonthPeriodPaymentAmountFigu__c = 2;
        insert rr;
        List<String>  rrls = new List<String>();
        //String ids = rr.Id;
        rrls.add(rr.Id);

        Id execBTId = null;
    
        List<Repair_receipt__c>  rrs = [select Id,Name,DeadlineLastMonthPeriodPaymentAmountFigu__c,
                                        DeadlineLastMonthPeriodPaymentAmount__c
                                     from Repair_receipt__c];
        System.assertEquals(1235,rrs[0].DeadlineLastMonthPeriodPaymentAmount__c);
        System.assertEquals(2,rrs[0].DeadlineLastMonthPeriodPaymentAmountFigu__c);
        
        System.Test.StartTest();
        execBTId = Database.executeBatch(new RepairReceiptBatch(),10);
        System.Test.StopTest();
        
        rrs = [select Id,Name,DeadlineLastMonthPeriodPaymentAmountFigu__c,
                                        DeadlineLastMonthPeriodPaymentAmount__c
                                     from Repair_receipt__c];
        System.assertEquals(1235,rrs[0].DeadlineLastMonthPeriodPaymentAmount__c);
        System.assertEquals(1235,rrs[0].DeadlineLastMonthPeriodPaymentAmountFigu__c);
        //execBTId = Database.executeBatch(new RepairReceiptBatch(null));
        
        
        //System.Test.StopTest();
		}

	}	
	
}