From d8dc84a3d56df839895f1c417a4d9cbee763d262 Mon Sep 17 00:00:00 2001
From: 高章伟 <gaozhangwei@prec-tech.com>
Date: 星期五, 03 三月 2023 14:50:59 +0800
Subject: [PATCH] gzw 测试环境代码更新

---
 force-app/main/default/classes/LastbuyProductHandlerTest.cls |  181 ++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 161 insertions(+), 20 deletions(-)

diff --git a/force-app/main/default/classes/LastbuyProductHandlerTest.cls b/force-app/main/default/classes/LastbuyProductHandlerTest.cls
index 5a53235..8ed4a42 100644
--- a/force-app/main/default/classes/LastbuyProductHandlerTest.cls
+++ b/force-app/main/default/classes/LastbuyProductHandlerTest.cls
@@ -2,6 +2,7 @@
 private class LastbuyProductHandlerTest {
     @isTest 
 	static void TestMethod1() {
+
         Product2 pro = new Product2();
         pro.Name = 'Testname0215';
         pro.LastbuyProductFLG__c = false;
@@ -11,10 +12,48 @@
         pro1.Name = 'Testname0216';
         pro1.LastbuyProductFLG__c = false;
         insert pro1;
+
+        Address_Level__c al = new Address_Level__c();
+        al.Name = '鍖椾含';
+        al.Level1_Code__c = 'CN-99';
+        al.Level1_Sys_No__c = '999999';
+        insert al;
+        // 甯�
+        Address_Level2__c al2 = new Address_Level2__c();
+        al2.Level1_Code__c = 'CN-99';
+        al2.Level1_Sys_No__c = '999999';
+        al2.Level1_Name__c = '鍖椾含';
+        al2.Name = '娴锋穩鍖�';
+        al2.Level2_Code__c = 'CN-9999';
+        al2.Level2_Sys_No__c = '9999999';
+        al2.Address_Level__c = al.id;
+        insert al2;
+
+        Account company = new Account();
+        company.Name = 'aiueo鐥呴櫌';
+        company.RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('HP').getRecordTypeId();
+        company.State_Master__c = al.Id;
+        company.City_Master__c = al2.Id;
+        insert company;
+        
+        Account sct = [Select Id, Name, Department_Class_Label__c, Sys_Dept_Name_Change_Chk__c from Account where Parent.Id = :company.Id and RecordTypeId = :Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Department_Class_BF').getRecordTypeId() Limit 1];
+        
+        Account depart = new Account();
+        depart.RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Department_BF').getRecordTypeId();
+        depart.Name = '*';
+        depart.Department_Name__c = 'aiueo瑷虹檪绉�';
+        depart.ParentId = sct.Id;
+        depart.Department_Class__c = sct.Id;
+        depart.Hospital__c = company.Id;
+        insert depart;
+        StaticParameter.EscapeOpportunityBefUpdTrigger = true;
+        Opportunity opp1 = new Opportunity(Name = 'aiueo鍟嗚珖', StageName = 'contact', CloseDate=Date.today(), SAP_Send_OK__c = false, AccountId = depart.Id);
+        insert opp1;
         
         LastbuyProduct__c lbp = new LastbuyProduct__c();
         lbp.Name = 'Test0215';
         lbp.ProductName__c = pro.Id;
+        lbp.InquiryCode__c = opp1.Id;
         lbp.effectiveFLG__c = true;
         insert lbp;
 
@@ -24,26 +63,128 @@
         lbp.effectiveFLG__c = true;
         update lbp;
 
-        LastbuyProduct__c lbp1 = new LastbuyProduct__c();
-        lbp1.Name = 'Test0216';
-        lbp1.ProductName__c = pro1.Id;
-        lbp1.effectiveFLG__c = true;
-        insert lbp1;
-
-        LastbuyProduct__c lbp2 = new LastbuyProduct__c();
-        lbp2.Name = 'Test0217';
-        lbp2.ProductName__c = pro1.Id;
-        lbp2.effectiveFLG__c = true;
-        insert lbp2;
-
-        lbp1.effectiveFLG__c = false;
-        update lbp1;
-
-        lbp2.ProductName__c = pro.Id;
-        update lbp2;
-
-        delete lbp1;
-
+        delete lbp;
     }
 
+    @isTest 
+    static void TestMethod2() {
+
+        Product2 pro = new Product2();
+        pro.Name = 'Testname0215';
+        pro.LastbuyProductFLG__c = false;
+        insert pro;
+
+        Address_Level__c al = new Address_Level__c();
+        al.Name = '鍖椾含';
+        al.Level1_Code__c = 'CN-99';
+        al.Level1_Sys_No__c = '999999';
+        insert al;
+        // 甯�
+        Address_Level2__c al2 = new Address_Level2__c();
+        al2.Level1_Code__c = 'CN-99';
+        al2.Level1_Sys_No__c = '999999';
+        al2.Level1_Name__c = '鍖椾含';
+        al2.Name = '娴锋穩鍖�';
+        al2.Level2_Code__c = 'CN-9999';
+        al2.Level2_Sys_No__c = '9999999';
+        al2.Address_Level__c = al.id;
+        insert al2;
+
+        Account company = new Account();
+        company.Name = 'aiueo鐥呴櫌';
+        company.RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('HP').getRecordTypeId();
+        company.State_Master__c = al.Id;
+        company.City_Master__c = al2.Id;
+        insert company;
+        
+        Account sct = [Select Id, Name, Department_Class_Label__c, Sys_Dept_Name_Change_Chk__c from Account where Parent.Id = :company.Id and RecordTypeId = :Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Department_Class_BF').getRecordTypeId() Limit 1];
+        
+        Account depart = new Account();
+        depart.RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Department_BF').getRecordTypeId();
+        depart.Name = '*';
+        depart.Department_Name__c = 'aiueo瑷虹檪绉�';
+        depart.ParentId = sct.Id;
+        depart.Department_Class__c = sct.Id;
+        depart.Hospital__c = company.Id;
+        insert depart;
+        StaticParameter.EscapeOpportunityBefUpdTrigger = true;
+        Opportunity opp1 = new Opportunity(Name = 'aiueo鍟嗚珖', StageName = 'contact', CloseDate=Date.today(), SAP_Send_OK__c = true, AccountId = depart.Id);
+        insert opp1;
+
+        Opportunity opp2 = new Opportunity(Name = 'aiueo鍟嗚珖', StageName = 'contact', CloseDate=Date.today(), SAP_Send_OK__c = false, AccountId = depart.Id);
+        insert opp2;
+
+        LastbuyProduct__c lbp = new LastbuyProduct__c();
+        lbp.Name = 'Test0215';
+        lbp.ProductName__c = pro.Id;
+        lbp.InquiryCode__c = opp1.Id;
+        lbp.effectiveFLG__c = true;
+        insert lbp;
+
+        try{
+            lbp.InquiryCode__c = opp2.Id;
+            update lbp;
+        } catch (Exception e) {
+            
+        }
+    }
+
+    @isTest 
+    static void TestMethod3() {
+
+        Product2 pro = new Product2();
+        pro.Name = 'Testname0215';
+        pro.LastbuyProductFLG__c = false;
+        insert pro;
+
+        Address_Level__c al = new Address_Level__c();
+        al.Name = '鍖椾含';
+        al.Level1_Code__c = 'CN-99';
+        al.Level1_Sys_No__c = '999999';
+        insert al;
+        // 甯�
+        Address_Level2__c al2 = new Address_Level2__c();
+        al2.Level1_Code__c = 'CN-99';
+        al2.Level1_Sys_No__c = '999999';
+        al2.Level1_Name__c = '鍖椾含';
+        al2.Name = '娴锋穩鍖�';
+        al2.Level2_Code__c = 'CN-9999';
+        al2.Level2_Sys_No__c = '9999999';
+        al2.Address_Level__c = al.id;
+        insert al2;
+
+        Account company = new Account();
+        company.Name = 'aiueo鐥呴櫌';
+        company.RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('HP').getRecordTypeId();
+        company.State_Master__c = al.Id;
+        company.City_Master__c = al2.Id;
+        insert company;
+        
+        Account sct = [Select Id, Name, Department_Class_Label__c, Sys_Dept_Name_Change_Chk__c from Account where Parent.Id = :company.Id and RecordTypeId = :Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Department_Class_BF').getRecordTypeId() Limit 1];
+        
+        Account depart = new Account();
+        depart.RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Department_BF').getRecordTypeId();
+        depart.Name = '*';
+        depart.Department_Name__c = 'aiueo瑷虹檪绉�';
+        depart.ParentId = sct.Id;
+        depart.Department_Class__c = sct.Id;
+        depart.Hospital__c = company.Id;
+        insert depart;
+        StaticParameter.EscapeOpportunityBefUpdTrigger = true;
+        Opportunity opp1 = new Opportunity(Name = 'aiueo鍟嗚珖', StageName = 'contact', CloseDate=Date.today(), SAP_Send_OK__c = true, AccountId = depart.Id);
+        insert opp1;
+
+        LastbuyProduct__c lbp = new LastbuyProduct__c();
+        lbp.Name = 'Test0215';
+        lbp.ProductName__c = pro.Id;
+        lbp.InquiryCode__c = opp1.Id;
+        lbp.effectiveFLG__c = true;
+        insert lbp;
+
+        try{
+            delete lbp;
+        } catch (Exception e) {
+            
+        }
+    }
 }
\ No newline at end of file

--
Gitblit v1.9.1