高章伟
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
@isTest
private class ProductScoreTableHistoryHandlerTest {
    private static void setdata(){
        System.runAs(new User(Id = Userinfo.getUserId())) {
            Product_Score_Table__c [] pstList = new List<Product_Score_Table__c>();
            Product_Score_Table__c pst01 = new Product_Score_Table__c(
                OCM_Term__c = '153P',
                Plan_Category3__c = 'ERCP',
                Category3__c = 'ERCP',
                Category4__c = '导丝'
            );
            pstList.add(pst01);
 
            for(Product_Score_Table__c pst: pstList) {
                pst.UniqueKey__c = pst.OCM_Term__c+':'+pst.Category3__c+':'+pst.Category4__c;
            }
            insert pstList;
 
            Product_CategoryPrice_Table__c [] psctList = new List<Product_CategoryPrice_Table__c>();
            Product_CategoryPrice_Table__c psct01 = new Product_CategoryPrice_Table__c(
                OCM_Term__c = '153P',
                Category3__c = 'ERCP',
                Category4__c = '导丝',
                Product_Amount__c = 5,
                Product_Total_Price__c = 1000
            );
            psctList.add(psct01);
 
            for(Product_CategoryPrice_Table__c psct: psctList) {
                psct.UniqueKey__c = psct.OCM_Term__c+':'+psct.Category3__c+':'+psct.Category4__c;
            }
            insert psctList;
        }
    }
 
    private static testMethod void ProductScoreTableHistoryHandler01() {
        setdata();
 
        Id PSTH_RecordTypeId = Schema.SObjectType.Product_Score_Table_History__c.getRecordTypeInfosByDeveloperName().get('TargetPDCA').getRecordTypeId();
 
 
        Test.startTest();
 
        String uniqueKey = 'T:153P:半期:医院管理编码:用户ID:ERCP:导丝';
        Product_Score_Table__c pst = [SELECT Id FROM Product_Score_Table__c WHERE UniqueKey__c = '153P:ERCP:导丝' LIMIT 1];
        Product_Score_Table_History__c [] psthList = new List<Product_Score_Table_History__c>();
        Product_Score_Table_History__c psth01 = new Product_Score_Table_History__c(
            UniqueKey__c = uniqueKey,
            Qty__c = 5,
            RecordTypeId = PSTH_RecordTypeId,
            Product_Score_Table__c = pst.Id,
            Plan_Date__c = Date.newInstance(Date.today().year(),Date.today().month(),1)
        );
        psthList.add(psth01);
        insert psthList;
        Test.stopTest();
 
        System.runAs(new User(Id = Userinfo.getUserId())) {
            Product_Score_Table_History__c psth = [SELECT Category4_Avg_Price__c FROM Product_Score_Table_History__c WHERE UniqueKey__c = :uniqueKey];
            System.assertEquals(100.00, psth.Category4_Avg_Price__c);
        }
 
    }
}