高章伟
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
@isTest
private class AccountUpEffectiveContractBatchTest
{
    @isTest
    static void itShould()
    {
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店'];
        if (rectCo.size() == 0) {
            return;
        }
 
        List<RecordType> rectContract = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '契約'];
        if (rectCo.size() == 0) {
            return;
        }
        //经销商
        Account myAccount1 = new Account(name='Testaccount001',
                                        Dealer_discount__c =20,
                                        RecordTypeId = rectCo[0].Id);
        insert myAccount1;
        //经销商有效合同
        Account myAccount2 = new Account(name='Testaccount002',
                                            RecordTypeId = rectContract[0].Id,
                                            Contract_Decide_Start_Date__c = Date.today().addDays(-1),
                                            Contract_Decide_End_Date__c =Date.today().addDays(1),
                                            Agent_Ref__c =myAccount1.Id,
                                            ParentId =myAccount1.Id,ET_SP_Dealer__c = true);
        insert myAccount2;
 
        Account acc = [select id,Agency_With_EffectiveContract__c from Account where id = :myAccount1.Id ];
        System.assertEquals(true, acc.Agency_With_EffectiveContract__c);
        myAccount1.Agency_With_EffectiveContract__c = false;
        update myAccount1;
        System.Test.StartTest();
        Id execBTId = Database.executeBatch(new AccountUpEffectiveContractBatch(),20);
        System.Test.StopTest();
        acc = [select id,Agency_With_EffectiveContract__c from Account where id = :myAccount1.Id ];
        System.assertEquals(true, acc.Agency_With_EffectiveContract__c);
    }
 
    @isTest
    static void itShould02()
    {
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店'];
        if (rectCo.size() == 0) {
            return;
        }
 
        List<RecordType> rectContract = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '契約'];
        if (rectCo.size() == 0) {
            return;
        }
        //经销商
        Account myAccount1 = new Account(name='Testaccount001',
                                        Dealer_discount__c =20,
                                        RecordTypeId = rectCo[0].Id);
        insert myAccount1;
        //经销商有效合同
        Account myAccount2 = new Account(name='Testaccount002',
                                            RecordTypeId = rectContract[0].Id,
                                            Contract_Decide_Start_Date__c = Date.today().addDays(-1),
                                            Contract_Decide_End_Date__c =Date.today().addDays(1),
                                            Agent_Ref__c =myAccount1.Id,
                                            ParentId =myAccount1.Id,ET_SP_Dealer__c = false);
        insert myAccount2;
 
        Account acc = [select id,Agency_With_EffectiveContract__c from Account where id = :myAccount1.Id ];
        System.assertEquals(false, acc.Agency_With_EffectiveContract__c);
        myAccount1.Agency_With_EffectiveContract__c = true;
        update myAccount1;
        System.Test.StartTest();
        Id execBTId = Database.executeBatch(new AccountUpEffectiveContractBatch(),20);
        System.Test.StopTest();
        acc = [select id,Agency_With_EffectiveContract__c from Account where id = :myAccount1.Id ];
        System.assertEquals(true, acc.Agency_With_EffectiveContract__c);
    }
}