高章伟
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
89
90
91
92
@isTest
private class PowerBIUpdateBatchTest {
    private static Product2 product = null;
    private static Id pricebookId = ControllerUtil.getStandardPricebook().Id;
 
    static {
        product = new Product2( Name='テスト商品');
        insert product;
    }
 
    private static PricebookEntry buildPB(String input) {
        PricebookEntry entry = new PricebookEntry(Pricebook2Id=pricebookId, Product2Id=product.Id);
        entry.UnitPrice = 0;
        entry.IsActive = true;
        entry.UseStandardPrice = false;
        entry.CurrencyIsoCode = input;
        insert entry;
        return entry;
    }
 
    private static void setuserset(){
        PowerBISyncDefine__c oppset = new PowerBISyncDefine__c();
        oppset.Name = 'Opportunity';
        oppset.To_Table__c = 'BI_Opportunity__c';
        insert(oppset);
 
        PowerBISyncDefine__c oliset = new PowerBISyncDefine__c();
        oliset.Name = 'OpportunityLineItem';
        oliset.To_Table__c = 'BI_OpportunityLineItem__c';
        insert(oliset);
    }
 
    static testMethod void myUnitTest() {
        setuserset();
 
        Opportunity opp1 = new Opportunity(Name='aiueo1', StageName='引合', CurrencyIsoCode='CNY', CloseDate=Date.today());
        insert opp1;
 
        PricebookEntry entryCNY = buildPB('CNY');
 
        OpportunityLineItem oli1 = new OpportunityLineItem(OpportunityId=opp1.Id, Name__c='oli1', Quantity=21, UnitPrice=100, PricebookEntryId=entryCNY.Id);
        insert oli1;
 
        List<BI_OpportunityLineItem__c> bi_oli1 = [select id, ShareWithPowerBI__c, ShareWithPowerBIFormula__c, ShareWithPowerBI_NeedUpd__c from BI_OpportunityLineItem__c where OpportunityId__c = :opp1.Id];
 
        //System.assertEquals(true, bi_oli1[0].ShareWithPowerBI__c);
        //System.assertEquals(true, bi_oli1[0].ShareWithPowerBIFormula__c);
        //System.assertEquals(false, bi_oli1[0].ShareWithPowerBI_NeedUpd__c);
 
        opp1.StageName = '出荷';
        update opp1;
 
        List<BI_OpportunityLineItem__c> bi_oli2 = [select id, ShareWithPowerBI__c, ShareWithPowerBIFormula__c, ShareWithPowerBI_NeedUpd__c from BI_OpportunityLineItem__c where OpportunityId__c = :opp1.Id];
        //System.assertEquals(true, bi_oli2.ShareWithPowerBI__c);
        //System.assertEquals(false, bi_oli2.ShareWithPowerBIFormula__c);
        //System.assertEquals(true, bi_oli2.ShareWithPowerBI_NeedUpd__c);
 
        Id execBTId = Database.executeBatch(new PowerBIUpdateBatch(opp1.Id), 100);
    }
 
    // 2021-03-11  mzy  add  SFDC合并调查Batch  start
    static testMethod void myUnitTest2() {
        setuserset();
 
        Opportunity opp1 = new Opportunity(Name='aiueo1', StageName='引合', CurrencyIsoCode='CNY', CloseDate=Date.today());
        insert opp1;
 
        PricebookEntry entryCNY = buildPB('CNY');
 
        OpportunityLineItem oli1 = new OpportunityLineItem(OpportunityId=opp1.Id, Name__c='oli1', Quantity=21, UnitPrice=100, PricebookEntryId=entryCNY.Id);
        insert oli1;
 
        opp1.StageName = '完了';
        update opp1;
 
        BI_OpportunityLineItem__c bo = new BI_OpportunityLineItem__c();
        bo.OpportunityId__c = opp1.Id;
        bo.Name = 'testBI';
        bo.PowerBI_Source_Id__c = '00k1000000rHneEAAz';
        bo.ShareWithPowerBI__c = true;
        insert bo;
 
        //System.assertEquals(null, bo.ShareWithPowerBIFormula__c);  //false
        //System.assertEquals(false, bo.ShareWithPowerBI__c);    //true
        //System.assertEquals(false, bo.ShareWithPowerBI_NeedUpd__c);        
 
        List<BI_OpportunityLineItem__c> bi_oli1 = [select id, ShareWithPowerBI__c, ShareWithPowerBIFormula__c, ShareWithPowerBI_NeedUpd__c from BI_OpportunityLineItem__c where OpportunityId__c = :opp1.Id];
 
        Id execBTId = Database.executeBatch(new PowerBIUpdateBatch(true), 100);
    }
    // 2021-03-11  mzy  add  SFDC合并调查Batch  end
}