@isTest private class ReceivingNoteStockInControllerTest { static ReceivingNoteTestDataFactory factory; /** @description 安装master数据 */ @testSetup static void setupMasterData(){ factory = new ReceivingNoteTestDataFactory(); factory.setupMasterData(); } /** @param typeStringListString 格式:'备品类型,管理种类;备品类型,管理种类...' @description 造出指定类型的清单数据,并插入数据库 */ static void setupTestData(String typeStringListString){ factory = new ReceivingNoteTestDataFactory(); if(String.isBlank(typeStringListString)){ typeStringListString = '固定资产,个体管理;附属品,个体管理;附属品,数量管理;耗材,数量管理;低值易耗品,数量管理'; } List typeStringList = typeStringListString.split(';'); factory.setupReceivingNoteData(typeStringList); } /** @description 测试初始化页面 */ static testMethod void unitTestInit() { setupTestData('固定资产,个体管理'); ReceivingNoteSummary__c rns = factory.rnsMap.get('固定资产,个体管理'); PageReference ref = new PageReference('/apex/ReceivingNoteStockIn?id=' + rns.Id); Test.setCurrentPage(ref); ReceivingNoteStockInController controller = new ReceivingNoteStockInController(); Test.startTest(); controller.init(); System.assertEquals(1, controller.esdList.size()); Test.stopTest(); } /** @description 测试保存功能 */ static testMethod void unitTestSave() { // 状态调整为已入库指示 setupTestData('固定资产,个体管理'); // 数据确认 ReceivingNoteDetail__c rnd = factory.rndMap.get('固定资产,个体管理'); rnd.unknow_serial_NO_product__c = 'FALSE'; rnd.Loaner_accsessary__c = 'TRUE'; rnd.DataConfirmation__c = true; upsert rnd Product_Serial_No__c; // 收货 ReceivingNoteSummary__c rns = factory.rnsMap.get('固定资产,个体管理'); rns.Received_Confirm_Time__c = System.Now(); upsert rns Internal_Asset_number__c; // 清点 rnd.AcceptanceTime__c = System.Now(); rnd.AcceptanceResult__c = 'OK'; // 验收 rnd.Inspection_result_after__c = 'OK'; // 再确认 rnd.DataConfirmationAgain__c = true; rnd.Arrival_wh_Request_time__c = System.Now(); upsert rnd Product_Serial_No__c; PageReference ref = new PageReference('/apex/ReceivingNoteStockIn?id=' + rns.Id); Test.setCurrentPage(ref); ReceivingNoteStockInController controller = new ReceivingNoteStockInController(); controller.init(); System.assertEquals(1, controller.esdList.size()); // 保存前 ReceivingNoteStockInController.EsdInfo esdInfo = controller.esdList[0]; System.assertEquals(false,esdInfo.rec.Arrival_in_wh__c); System.assertEquals(null,esdInfo.rec.WH_location__c); System.assertEquals(true, esdInfo.editable); // 修改 Test.startTest(); esdInfo.rec.Arrival_in_wh__c = true; esdInfo.rec.WH_location__c = '123'; controller.save(); Test.stopTest(); // 检查保存结果 List rndList = [ SELECT Arrival_in_wh__c , WH_location__c FROM ReceivingNoteDetail__c ORDER BY SerialNumber__c ]; System.assertEquals(true,rndList[0].Arrival_in_wh__c); System.assertEquals('123',rndList[0].WH_location__c); System.assertEquals(false, controller.esdList[0].editable); } /** @description 一对一入库 */ static testMethod void unitTestSaveOneToOne() { setupTestData('固定资产,个体管理'); // 修改成一对一配套 Fixture_Set_Detail__c fsd0 = factory.fsdList[0]; Fixture_Set_Detail__c fsd1 = factory.fsdList[1]; fsd0.Is_Body__c = true; fsd1.Is_Body__c = false; fsd1.Is_OneToOne__c = true; update new Fixture_Set_Detail__c[] {fsd0, fsd1}; // 状态调整为已入库指示 ReceivingNoteSummary__c rns = factory.rnsMap.get('固定资产,个体管理'); ReceivingNoteDetail__c rnd = factory.rndMap.get('固定资产,个体管理'); rnd.unknow_serial_NO_product__c = 'TRUE'; rnd.Loaner_accsessary__c = 'TRUE'; rnd.DataConfirmation__c = true; ReceivingNoteDetail__c rnd1 = new ReceivingNoteDetail__c(); rnd1.DataMigration_Flag__c = true; rnd1.ReceivingNoteSummary__c = rns.Id; rnd1.FSD_Id__c = factory.fsdList[1].Id; rnd1.unknow_serial_NO_product__c = 'TRUE'; rnd1.Loaner_accsessary__c = 'TRUE'; rnd1.Fixture_Set_Detail__c = factory.fsdList[1].Id; rnd1.Product_Serial_No__c = 'SB-PRO-SERIAL-'+2; rnd1.passNo2__c = '02'; rnd1.passNo3__c = '2'; rnd1.SerialNumber__c = 'SB-ASSET-SERIAL-6'; rnd1.DataConfirmation__c = true; upsert new ReceivingNoteDetail__c[] {rnd, rnd1} Product_Serial_No__c; rns.Received_Confirm_Time__c = System.Now(); upsert rns Internal_Asset_number__c; rnd.AcceptanceTime__c = System.Now(); rnd.AcceptanceResult__c = 'OK'; rnd.Inspection_result_after__c = 'OK'; rnd.DataConfirmationAgain__c = true; rnd.Arrival_wh_Request_time__c = System.Now(); rnd1.AcceptanceTime__c = System.Now(); rnd1.AcceptanceResult__c = 'OK'; rnd1.Inspection_result_after__c = 'OK'; rnd1.DataConfirmationAgain__c = true; rnd1.Arrival_wh_Request_time__c = System.Now(); rnd1.Salesdepartment__c = '1.华北营业本部'; rnd1.Product_category__c = 'GI'; rnd1.Equipment_Type__c = '产品试用'; update new ReceivingNoteDetail__c[] {rnd, rnd1}; PageReference ref = new PageReference('/apex/ReceivingNoteStockIn?id=' + rns.Id); Test.setCurrentPage(ref); ReceivingNoteStockInController controller = new ReceivingNoteStockInController(); controller.init(); System.assertEquals(2, controller.esdList.size()); // 保存前 ReceivingNoteStockInController.EsdInfo esdInfo = controller.esdList[0]; System.assertEquals(false,esdInfo.rec.Arrival_in_wh__c); System.assertEquals(null,esdInfo.rec.WH_location__c); System.assertEquals(true, esdInfo.editable); ReceivingNoteStockInController.EsdInfo esdInfo1 = controller.esdList[1]; System.assertEquals(false,esdInfo1.rec.Arrival_in_wh__c); System.assertEquals(null,esdInfo1.rec.WH_location__c); System.assertEquals(true, esdInfo1.editable); // 修改 Test.startTest(); esdInfo.rec.Arrival_in_wh__c = true; esdInfo.rec.WH_location__c = '123'; esdInfo1.rec.Arrival_in_wh__c = true; esdInfo1.rec.WH_location__c = '321'; controller.save(); Test.stopTest(); // 检查保存结果 List rndList = [ SELECT Arrival_in_wh__c , WH_location__c FROM ReceivingNoteDetail__c ORDER BY Product_Serial_No__c ]; System.assertEquals(true,rndList[0].Arrival_in_wh__c); System.assertEquals('123',rndList[0].WH_location__c); System.assertEquals(false, controller.esdList[0].editable); System.assertEquals(true,rndList[1].Arrival_in_wh__c); System.assertEquals('321',rndList[1].WH_location__c); System.assertEquals(false, controller.esdList[1].editable); } /** @description 取照片 */ static testMethod void unitTestFetchPhotoStatus() { setupTestData('固定资产,个体管理'); ReceivingNoteSummary__c rns = factory.rnsMap.get('固定资产,个体管理'); ReceivingNoteDetail__c rnd = factory.rndMap.get('固定资产,个体管理'); rnd.Arrival_wh_Request_time__c = Datetime.now(); update rnd; PageReference ref = new PageReference('/apex/ReceivingNoteStockIn?id=' + rns.Id); Test.setCurrentPage(ref); ReceivingNoteStockInController controller = new ReceivingNoteStockInController(); Test.startTest(); controller.init(); controller.fetchPhotoStatus(); Test.stopTest(); System.assertEquals(1, controller.esdList.size()); System.assertEquals(true, controller.esdList[0].editable); } /** @description 耗材入库 */ static testMethod void unitTestSaveConsum() { // 状态调整为已入库指示 setupTestData('耗材,数量管理'); // 数据确认 ReceivingNoteDetail__c rnd = factory.rndMap.get('耗材,数量管理'); rnd.unknow_serial_NO_product__c = 'FALSE'; rnd.Loaner_accsessary__c = 'TRUE'; rnd.DataConfirmation__c = true; upsert rnd Product_Serial_No__c; // 收货 ReceivingNoteSummary__c rns = factory.rnsMap.get('耗材,数量管理'); rns.Received_Confirm_Time__c = System.Now(); upsert rns Internal_Asset_number__c; // 清点 rnd.AcceptanceTime__c = System.Now(); rnd.AcceptanceResult__c = 'OK'; // 验收 rnd.Inspection_result_after__c = 'OK'; // 再确认 rnd.DataConfirmationAgain__c = true; rnd.Arrival_wh_Request_time__c = System.Now(); upsert rnd Product_Serial_No__c; PageReference ref = new PageReference('/apex/ReceivingNoteStockIn?id=' + rns.Id); Test.setCurrentPage(ref); ReceivingNoteStockInController controller = new ReceivingNoteStockInController(); controller.init(); System.assertEquals(1, controller.esdList.size()); // 保存前 ReceivingNoteStockInController.EsdInfo esdInfo = controller.esdList[0]; System.assertEquals(false,esdInfo.rec.Arrival_in_wh__c); System.assertEquals(null,esdInfo.rec.WH_location__c); System.assertEquals(true, esdInfo.editable); // 修改 Test.startTest(); esdInfo.rec.Arrival_in_wh__c = true; esdInfo.rec.WH_location__c = '123'; controller.save(); Test.stopTest(); // 检查保存结果 List rndList = [ SELECT Arrival_in_wh__c , WH_location__c FROM ReceivingNoteDetail__c ORDER BY SerialNumber__c ]; System.assertEquals(true,rndList[0].Arrival_in_wh__c); System.assertEquals('123',rndList[0].WH_location__c); System.assertEquals(false, controller.esdList[0].editable); } /** @description 个体变体入库,直接对接口Asset修改 */ static testMethod void unitTestBiantiSave() { // 状态调整为已入库指示 setupTestData('固定资产,个体管理'); // 数据确认 ReceivingNoteDetail__c rnd = factory.rndMap.get('固定资产,个体管理'); rnd.unknow_serial_NO_product__c = 'FALSE'; rnd.Loaner_accsessary__c = 'TRUE'; rnd.DataConfirmation__c = true; rnd.Fixture_Arrival_Process__c = '变体'; rnd.Fixture_Arrival_Product__c = factory.proList[2].Id; upsert rnd Product_Serial_No__c; // 收货 ReceivingNoteSummary__c rns = factory.rnsMap.get('固定资产,个体管理'); rns.Received_Confirm_Time__c = System.Now(); upsert rns Internal_Asset_number__c; // 清点 rnd.AcceptanceTime__c = System.Now(); rnd.AcceptanceResult__c = 'OK'; // 验收 rnd.Inspection_result_after__c = 'OK'; // 再确认 rnd.DataConfirmationAgain__c = true; rnd.Arrival_wh_Request_time__c = System.Now(); upsert rnd Product_Serial_No__c; PageReference ref = new PageReference('/apex/ReceivingNoteStockIn?id=' + rns.Id); Test.setCurrentPage(ref); ReceivingNoteStockInController controller = new ReceivingNoteStockInController(); controller.init(); System.assertEquals(1, controller.esdList.size()); // 保存前 ReceivingNoteStockInController.EsdInfo esdInfo = controller.esdList[0]; System.assertEquals(false,esdInfo.rec.Arrival_in_wh__c); System.assertEquals(null,esdInfo.rec.WH_location__c); System.assertEquals(true, esdInfo.editable); // 入库前的Asset List assList = [SELECT Id,Fixture_Model_No_F__c,AccountId,Product2Id,Product_Old__c FROM Asset WHERE Id=:esdInfo.rec.RNDAssert__c]; System.assertEquals(factory.accountMap.get('备品(待收货)').Id, assList[0].AccountId) ; System.assertEquals(null, assList[0].Product_Old__c) ; System.assertEquals(factory.proList[0].Id, assList[0].Product2Id) ; // 修改 Test.startTest(); esdInfo.rec.Arrival_in_wh__c = true; esdInfo.rec.WH_location__c = '123'; controller.save(); Test.stopTest(); // 检查保存结果 List rndList = [ SELECT Arrival_in_wh__c , WH_location__c FROM ReceivingNoteDetail__c ORDER BY SerialNumber__c ]; System.assertEquals(true,rndList[0].Arrival_in_wh__c); System.assertEquals('123',rndList[0].WH_location__c); System.assertEquals(false, controller.esdList[0].editable); // 入库后Asset assList = [SELECT Id,Fixture_Model_No_F__c,AccountId,Product2Id,Product_Old__c FROM Asset WHERE Id=:esdInfo.rec.RNDAssert__c]; System.assertEquals(factory.accountMap.get('备品').Id, assList[0].AccountId) ; System.assertEquals(factory.proList[0].Id, assList[0].Product_Old__c) ; System.assertEquals(factory.proList[2].Id, assList[0].Product2Id) ; } /** @description 合并入库 */ static testMethod void unitTestHebingSave() { // 状态调整为已入库指示 setupTestData('固定资产,个体管理'); // 数据确认 ReceivingNoteDetail__c rnd = factory.rndMap.get('固定资产,个体管理'); rnd.unknow_serial_NO_product__c = 'FALSE'; rnd.Loaner_accsessary__c = 'TRUE'; rnd.DataConfirmation__c = true; rnd.Fixture_Arrival_Process__c = '合并'; upsert rnd Product_Serial_No__c; // 收货 ReceivingNoteSummary__c rns = factory.rnsMap.get('固定资产,个体管理'); rns.Received_Confirm_Time__c = System.Now(); upsert rns Internal_Asset_number__c; // 清点 rnd.AcceptanceTime__c = System.Now(); rnd.AcceptanceResult__c = 'OK'; // 验收 rnd.Inspection_result_after__c = 'OK'; // 再确认 rnd.DataConfirmationAgain__c = true; rnd.Arrival_wh_Request_time__c = System.Now(); upsert rnd Product_Serial_No__c; PageReference ref = new PageReference('/apex/ReceivingNoteStockIn?id=' + rns.Id); Test.setCurrentPage(ref); ReceivingNoteStockInController controller = new ReceivingNoteStockInController(); controller.init(); System.assertEquals(1, controller.esdList.size()); // 保存前 ReceivingNoteStockInController.EsdInfo esdInfo = controller.esdList[0]; System.assertEquals(false,esdInfo.rec.Arrival_in_wh__c); System.assertEquals(null,esdInfo.rec.WH_location__c); System.assertEquals(true, esdInfo.editable); // 变体前的Asset List assList = [SELECT Id,Fixture_Model_No_F__c,AccountId FROM Asset WHERE Id=:esdInfo.rec.RNDAssert__c]; System.assertEquals(factory.accountMap.get('备品(待收货)').Id, assList[0].AccountId) ; // 修改 Test.startTest(); esdInfo.rec.Arrival_in_wh__c = true; esdInfo.rec.WH_location__c = '123'; controller.save(); Test.stopTest(); // 检查保存结果 List rndList = [ SELECT Arrival_in_wh__c , WH_location__c FROM ReceivingNoteDetail__c ORDER BY SerialNumber__c ]; System.assertEquals(true,rndList[0].Arrival_in_wh__c); System.assertEquals('123',rndList[0].WH_location__c); System.assertEquals(false, controller.esdList[0].editable); // 变体前的Asset assList = [SELECT Id,Fixture_Model_No_F__c,AccountId FROM Asset WHERE Id=:esdInfo.rec.RNDAssert__c]; System.assertEquals(factory.accountMap.get('备品(已收货)').Id, assList[0].AccountId) ; } }