|  |  |  | 
|---|
|  |  |  | @isTest | 
|---|
|  |  |  | private class LexConsumableAccountSOQLTest { | 
|---|
|  |  |  | @testSetup | 
|---|
|  |  |  | static void testInfo() { | 
|---|
|  |  |  | @testSetup | 
|---|
|  |  |  | static void testInfo(){ | 
|---|
|  |  |  | User userTest; | 
|---|
|  |  |  | Account accountItem; | 
|---|
|  |  |  | User thisUser = [SELECT Id FROM User WHERE Id = :UserInfo.getUserId()]; | 
|---|
|  |  |  | System.runAs(thisUser) { | 
|---|
|  |  |  | List<RecordType> rectCo = [ | 
|---|
|  |  |  | SELECT Id | 
|---|
|  |  |  | FROM RecordType | 
|---|
|  |  |  | WHERE IsActive = TRUE AND SobjectType = 'Account' AND Name = '販売店' | 
|---|
|  |  |  | ]; | 
|---|
|  |  |  | User thisUser = [SELECT Id FROM User WHERE Id =:UserInfo.getUserId()]; | 
|---|
|  |  |  | System.runAs(thisUser){ | 
|---|
|  |  |  | List<RecordType> rectCo = [SELECT Id FROM RecordType WHERE IsActive = true AND SobjectType = 'Account' AND Name = '販売店']; | 
|---|
|  |  |  | if (rectCo.size() == 0) { | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Profile prof = [ | 
|---|
|  |  |  | SELECT Id | 
|---|
|  |  |  | FROM Profile | 
|---|
|  |  |  | WHERE Name = '901_经销商社区普通权限_2重验证(ET)' | 
|---|
|  |  |  | ]; | 
|---|
|  |  |  | accountItem = new Account( | 
|---|
|  |  |  | Name = 'Testaccount002', | 
|---|
|  |  |  | Dealer_discount__c = 20, | 
|---|
|  |  |  | RecordTypeId = rectCo[0].Id, | 
|---|
|  |  |  | Product_Limit_Date__c = 'Test01|5|55,Test02|2|4', | 
|---|
|  |  |  | AgentCode_Ext__c = '9999900' | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | Profile prof = [SELECT Id FROM Profile WHERE Name ='901_经销商社区普通权限_2重验证(ET)']; | 
|---|
|  |  |  | accountItem = new Account(Name='Testaccount002', Dealer_discount__c = 20, RecordTypeId = rectCo[0].Id, Product_Limit_Date__c = 'Test01|5|55,Test02|2|4', AgentCode_Ext__c = '9999900'); | 
|---|
|  |  |  | insert accountItem; | 
|---|
|  |  |  | Contact core = new Contact( | 
|---|
|  |  |  | email = 'jplumber@salesforce.com', | 
|---|
|  |  |  | firstname = 'Joe', | 
|---|
|  |  |  | lastname = 'Plumber', | 
|---|
|  |  |  | accountId = accountItem.id | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | Contact core = new Contact(email='jplumber@salesforce.com', firstname='Joe', lastname='Plumber', accountId = accountItem.id); | 
|---|
|  |  |  | insert core; | 
|---|
|  |  |  | userTest = new User( | 
|---|
|  |  |  | ContactId = core.id, | 
|---|
|  |  |  | Alias = 'newUser', | 
|---|
|  |  |  | Email = 'newuser@testorg.com', | 
|---|
|  |  |  | EmailEncodingKey = 'UTF-8', | 
|---|
|  |  |  | LastName = 'TestUser', | 
|---|
|  |  |  | LanguageLocaleKey = 'zh_CN', | 
|---|
|  |  |  | LocaleSidKey = 'zh_CN', | 
|---|
|  |  |  | ProfileId = prof.Id, | 
|---|
|  |  |  | TimeZoneSidKey = 'Asia/Shanghai', | 
|---|
|  |  |  | UserName = 'testUser@testorg.com', | 
|---|
|  |  |  | UserPro_Type__c = 'ENG', | 
|---|
|  |  |  | Work_Location__c = '北京' | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | userTest = New User(ContactId = core.id, Alias = 'newUser', Email='newuser@testorg.com', EmailEncodingKey='UTF-8', LastName='TestUser', LanguageLocaleKey='zh_CN', LocaleSidKey='zh_CN', ProfileId = prof.Id, TimeZoneSidKey='Asia/Shanghai', UserName='testUser@testorg.com', UserPro_Type__c='ENG', Work_Location__c='北京'); | 
|---|
|  |  |  | insert userTest; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | System.runAs(userTest) { | 
|---|
|  |  |  | Product2 prod01 = new Product2( | 
|---|
|  |  |  | Name = 'Test01', | 
|---|
|  |  |  | ProductCode = 'Test01', | 
|---|
|  |  |  | Asset_Model_No__c = 'Test01', | 
|---|
|  |  |  | SFDA_Status__c = '有効', | 
|---|
|  |  |  | Dealer_special_Object__c = true, | 
|---|
|  |  |  | SFDA_Approbation_No__c = '12124', | 
|---|
|  |  |  | Packing_list_manual__c = 1, | 
|---|
|  |  |  | SFDA_Expiration_Date__c = Date.today(), | 
|---|
|  |  |  | Manual_Entry__c = false | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | Product2 prod02 = new Product2( | 
|---|
|  |  |  | Name = 'Test02', | 
|---|
|  |  |  | ProductCode = 'Test02', | 
|---|
|  |  |  | Asset_Model_No__c = 'Test02', | 
|---|
|  |  |  | SFDA_Status__c = '有効', | 
|---|
|  |  |  | Dealer_special_Object__c = true, | 
|---|
|  |  |  | SFDA_Approbation_No__c = '12124', | 
|---|
|  |  |  | Packing_list_manual__c = 1, | 
|---|
|  |  |  | SFDA_Expiration_Date__c = Date.today(), | 
|---|
|  |  |  | Manual_Entry__c = false | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | insert new List<Product2>{ prod01, prod02 }; | 
|---|
|  |  |  | Product2__c pro1 = new Product2__c(Name = 'Pro001', OT_CODE_Text__c = 'Test001', Product2__c = prod01.Id); | 
|---|
|  |  |  | Product2__c pro2 = new Product2__c(Name = 'Pro002', OT_CODE_Text__c = 'Test002', Product2__c = prod02.Id); | 
|---|
|  |  |  | insert new List<Product2__c>{ pro1, pro2 }; | 
|---|
|  |  |  | System.runAs(userTest){ | 
|---|
|  |  |  | Product2 prod01 = new Product2(Name='Test01',ProductCode='Test01',Asset_Model_No__c = 'Test01',SFDA_Status__c = '有効',Dealer_special_Object__c = true,SFDA_Approbation_No__c = '12124',Packing_list_manual__c = 1,SFDA_Expiration_Date__c= Date.today(),Manual_Entry__c = false); | 
|---|
|  |  |  | Product2 prod02 = new Product2(Name='Test02',ProductCode='Test02',Asset_Model_No__c = 'Test02',SFDA_Status__c = '有効',Dealer_special_Object__c = true,SFDA_Approbation_No__c = '12124',Packing_list_manual__c = 1,SFDA_Expiration_Date__c= Date.today(),Manual_Entry__c = false); | 
|---|
|  |  |  | insert new Product2[]{prod01,prod02}; | 
|---|
|  |  |  | Product2__c pro1 = new Product2__c(Name='Pro001',OT_CODE_Text__c='Test001',Product2__c = prod01.Id); | 
|---|
|  |  |  | Product2__c pro2 = new Product2__c(Name='Pro002',OT_CODE_Text__c='Test002',Product2__c = prod02.Id); | 
|---|
|  |  |  | insert new Product2__c[] {pro1, pro2}; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Consumable_order__c createId = new Consumable_order__c(); | 
|---|
|  |  |  | createId.Name = 'testMing1'; | 
|---|
|  |  |  | 
|---|
|  |  |  | createId.Delivery_detail_count__c = 5; | 
|---|
|  |  |  | createId.orderPattern__c = 'hospitalorder'; | 
|---|
|  |  |  | insert createId; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Consumable_Orderdetails__c> coListTest = new List<Consumable_Orderdetails__c>(); | 
|---|
|  |  |  | Consumable_Orderdetails__c conOrderDetail1 = new Consumable_Orderdetails__c(); | 
|---|
|  |  |  | conOrderDetail1.Name = 'testConOrderDetail1'; | 
|---|
|  |  |  | conOrderDetail1.Consumable_Arrivecount__c = 5; | 
|---|
|  |  |  | conOrderDetail1.Unitprice_To_agency__c = 0; | 
|---|
|  |  |  | conOrderDetail1.Unitprice_To_agency__c  = 0; | 
|---|
|  |  |  | conOrderDetail1.Delivery_List_RMB__c = 99; | 
|---|
|  |  |  | conOrderDetail1.Shipment_Count__c = 100; | 
|---|
|  |  |  | conOrderDetail1.Consumable_product__c = pro1.id; | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Consumable_Orderdetails__c conOrderDetail2 = new Consumable_Orderdetails__c(); | 
|---|
|  |  |  | conOrderDetail2.Name = 'testConOrderDetail2'; | 
|---|
|  |  |  | conOrderDetail1.Unitprice_To_agency__c = 0; | 
|---|
|  |  |  | conOrderDetail1.Unitprice_To_agency__c  = 0; | 
|---|
|  |  |  | conOrderDetail1.Delivery_List_RMB__c = 99; | 
|---|
|  |  |  | conOrderDetail2.Shipment_Count__c = 99; | 
|---|
|  |  |  | conOrderDetail2.Consumable_product__c = pro2.id; | 
|---|
|  |  |  | 
|---|
|  |  |  | coListTest.add(conOrderDetail2); | 
|---|
|  |  |  | insert coListTest; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | @isTest | 
|---|
|  |  |  | static void testGetAccountBySales() { | 
|---|
|  |  |  | static void testGetAccountBySales(){ | 
|---|
|  |  |  | System.Test.startTest(); | 
|---|
|  |  |  | DateTime thisDatetime = DateTime.newInstance(2023, 1, 1, 0, 0, 0); | 
|---|
|  |  |  | DateTime nextDatetime = DateTime.newInstance(2023, 6, 6, 0, 0, 0); | 
|---|
|  |  |  | DateTime thisDatetime = DateTime.newInstance(2023,1,1,00,00,00); | 
|---|
|  |  |  | DateTime nextDatetime = DateTime.newInstance(2023,6,6,00,00,00); | 
|---|
|  |  |  | AggregateResult[] arList = new List<AggregateResult>(); | 
|---|
|  |  |  | arList = LexConsumableAccountSOQL.getAccountBySales(thisDatetime, nextDatetime); | 
|---|
|  |  |  | arList = LexConsumableAccountSOQL.getAccountBySales(thisDatetime,nextDatetime); | 
|---|
|  |  |  | System.Test.stopTest(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | @isTest | 
|---|
|  |  |  | static void testGetAccountTotalSales() { | 
|---|
|  |  |  | static void testGetAccountTotalSales(){ | 
|---|
|  |  |  | System.Test.startTest(); | 
|---|
|  |  |  | DateTime thisDatetime = DateTime.newInstance(2023, 1, 1, 0, 0, 0); | 
|---|
|  |  |  | DateTime nextDatetime = DateTime.newInstance(2023, 6, 6, 0, 0, 0); | 
|---|
|  |  |  | DateTime thisDatetime = DateTime.newInstance(2023,1,1,00,00,00); | 
|---|
|  |  |  | DateTime nextDatetime = DateTime.newInstance(2023,6,6,00,00,00); | 
|---|
|  |  |  | AggregateResult[] saleAmountList = new List<AggregateResult>(); | 
|---|
|  |  |  | saleAmountList = LexConsumableAccountSOQL.getAccountTotalSales(thisDatetime, nextDatetime); | 
|---|
|  |  |  | saleAmountList = LexConsumableAccountSOQL.getAccountTotalSales(thisDatetime,nextDatetime); | 
|---|
|  |  |  | System.Test.stopTest(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|