@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);
|
}
|
|
}
|
}
|