高章伟
2022-02-18 8b5f4c6c281cfa548f92de52c8021e37aa81901e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
@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();
        }
 
    }    
    
}