@isTest
|
private class NFM401ControllerTest {
|
static Repair__c rpr;
|
static QIS_Report__c qis;
|
|
@testSetup
|
static void makeTestRepair() {
|
List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
|
if (rectCo.size() == 0) {
|
throw new ControllerUtil.myException('not found 病院 recodetype');
|
}
|
List<RecordType> rectSct = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 消化科'];
|
if (rectSct.size() == 0) {
|
throw new ControllerUtil.myException('not found 戦略科室分類 呼吸科 recodetype');
|
}
|
List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 消化科'];
|
if (rectDpt.size() == 0) {
|
throw new ControllerUtil.myException('not found 診療科 消化科 recodetype');
|
}
|
// テストデータ
|
Account company = new Account();
|
company.RecordTypeId = rectCo[0].Id;
|
company.Name = 'NFM105TestCompany';
|
upsert company;
|
Account section = [Select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where ParentId = :company.Id and RecordTypeId = :rectSct[0].Id];
|
|
Account depart = new Account();
|
depart.RecordTypeId = rectDpt[0].Id;
|
depart.Name = '*';
|
depart.Department_Name__c = 'NFM105TestDepart';
|
depart.ParentId = section.Id;
|
depart.Department_Class__c = section.Id;
|
depart.Hospital__c = company.Id;
|
upsert depart;
|
|
// 再取得
|
List<Account> accList = new List<Account>();
|
company = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Id = :company.Id];
|
accList.add(company);
|
accList.add(section);
|
depart = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Id = :depart.Id];
|
accList.add(depart);
|
|
// List<Product2> prdList = new List<Product2>();
|
Product2 prd1 = new Product2();
|
prd1.ProductCode_Ext__c = 'NFM105Prd1';
|
prd1.ProductCode = 'NFM105Prd1';
|
prd1.Repair_Product_Code__c = 'NFM105Prd1_RP';
|
prd1.Name = 'NFM105Prd1';
|
prd1.Manual_Entry__c = false;
|
// prdList.add(prd1);
|
Product2 prd2 = new Product2();
|
prd2.ProductCode_Ext__c = 'NFM105Prd2';
|
prd2.ProductCode = 'NFM105Prd2';
|
prd2.Repair_Product_Code__c = 'NFM105Prd2_RP';
|
prd2.Name = 'NFM105Prd2';
|
prd2.Manual_Entry__c = false;
|
// prdList.add(prd2);
|
insert new Product2[] {prd1,prd2};
|
|
Asset ast = new Asset();
|
ast.Name = 'NFM105Ast1';
|
ast.AccountId = depart.Id;
|
ast.Department_Class__c = section.Id;
|
ast.Hospital__c = company.Id;
|
ast.Product2Id = prd1.Id;
|
ast.SerialNumber = 'NFM105SerialNumber';
|
ast.Guarantee_period_for_products__c = Date.today();
|
ast.InstallDate = Date.today();
|
insert ast;
|
ast = [select Id, Name, Product_Serial_No__c, AccountId, Department_Class__c, Department_Class__r.Management_Code_Auto__c, Hospital__c, Product2Id, Product2.ProductCode, Product2.Repair_Product_Code__c, SerialNumber
|
from Asset
|
where Id = :ast.Id];
|
|
// User testUser = new User();
|
// testUser.Job_Category__c = '销售服务';
|
|
|
BatchIF_Transfer__c tr1 = new BatchIF_Transfer__c();
|
tr1.Table__c = 'Repair__c';
|
tr1.Column__c = 'ProblemOccurred__c';
|
tr1.External_Value__c = 'Receipt Inspection';
|
tr1.Internal_Value__c = '到货验收';
|
insert tr1;
|
|
BatchIF_Transfer__c tr2 = new BatchIF_Transfer__c();
|
tr2.Table__c = 'Repair__c';
|
tr2.Column__c = 'ifDeadHurt__c';
|
tr2.External_Value__c = 'Y';
|
tr2.Internal_Value__c = '有';
|
insert tr2;
|
|
BatchIF_Transfer__c tr3 = new BatchIF_Transfer__c();
|
tr3.Table__c = 'Repair__c';
|
tr3.Column__c = 'ReportAdverseEvents__c';
|
tr3.External_Value__c = 'Y';
|
tr3.Internal_Value__c = '有';
|
insert tr3;
|
|
rpr = new Repair__c();
|
rpr.PAE_Determine__c = 'PAE' ; //--
|
rpr.ifDeadHurt__c = '有'; //-- R1
|
rpr.PAE_DetermineAC__c = null; //--
|
rpr.SAPRepairNo__c = 'NFM105Rpr1';
|
rpr.Account__c = depart.Id;
|
rpr.Department_Class__c = section.Id;
|
rpr.Hospital__c = company.Id;
|
rpr.Delivered_Product__c = ast.Id;
|
rpr.Status__c = '1.受理完毕';
|
rpr.Incharge_Staff__c = Userinfo.getUserId();
|
rpr.Repair_Detail__c = 'test';
|
rpr.GeneratedPDFField__c = null;
|
rpr.AsyncData__c = true;
|
rpr.Complaint_Number__c = null;
|
rpr.ReportAdverseEvents__c = '有';
|
rpr.ProblemOccurred__c = '到货验收';
|
rpr.ifDeadHurt__c = '有';
|
rpr.ASReportedCode__c = 'TEST01,TEST02';
|
rpr.ASReportedCodeAC__c = 'TEST02,TEST04';
|
rpr.DateReceiptQuestions__c = Date.today();
|
rpr.Failure_Occurrence_Date__c = Date.today();
|
rpr.Repair_Ordered_Date__c = Date.today();
|
System.runAs(new User(Id = Userinfo.getUserId())){
|
insert rpr;
|
}
|
|
Attachment att = new Attachment();
|
att.ParentId = rpr.Id;
|
att.Name = 'test01';
|
att.Body = EncodingUtil.base64Decode('test02');
|
insert att;
|
|
|
qis = new QIS_Report__c();
|
qis.Damage_For_Doc_Or_Pat__c = '有'; //--
|
qis.PAE_Determine__c = 'PAE'; //-- Q1
|
qis.PAE_DetermineAC__c = null; //--
|
qis.Relation_With_The_Problem__c = '有可能';
|
qis.Report_For_Goz__c = '不知道';
|
qis.Damage_For_Doc_Or_Pat__c = '无';
|
qis.PAE_DetermineResultsText__c = 'PAE';
|
qis.OCSM_Nogoods__c = false;
|
qis.OCM_RC_RecievedDate__c = Date.today();
|
qis.ASReportedCode__c = 'G100,G200';
|
qis.ASReportedCodeAC__c = 'TEST1,TEST2';
|
qis.next_action__c = '无偿更换';
|
insert qis;
|
|
Attachment att1 = new Attachment();
|
att1.ParentId = qis.Id;
|
att1.Name = 'test02';
|
att1.Body = EncodingUtil.base64Decode('test02');
|
insert att1;
|
|
}
|
|
|
|
@isTest
|
static void testcallout1(){
|
List<Repair__c> list0 = [SELECT Id FROM Repair__c];
|
List<String> ids = new List<String>();
|
ids.add(list0.get(0).Id);
|
|
|
Test.startTest();
|
if(!Test.isRunningTest()){
|
LogAutoSendSchedule.assignOneMinute();
|
}
|
NFM401Controller.callout(null,null, ids,'R1');
|
// NFM401Controller.callout(null,null, ids,'Q1');
|
Test.stopTest();
|
}
|
|
@isTest
|
static void testcallout2(){
|
// StaticParameter.EscapeSyncProduct2Trigger = true;
|
StaticParameter.EscapeAccountTrigger = true;
|
StaticParameter.EscapeNFM001AgencyContractTrigger = true;
|
ControllerUtil.EscapeNFM001Trigger = true;
|
Oly_TriggerHandler.bypass('UpdateContractAimAmountHandler');
|
// makeTestRepair();
|
List<Repair__c> list0 = [SELECT Id FROM Repair__c];
|
rpr = list0.get(0);
|
//R2
|
rpr.ifDeadHurt__c = '无';
|
rpr.PAE_Determine__c = 'PAE';
|
rpr.PAE_DetermineAC__c = 'PAE';
|
rpr.Repair_Inspection_Date__c = Date.today();
|
rpr.PAE_DetermineResultsText__c ='nonPAE';
|
upsert rpr;
|
List<String> ids = new List<String>();
|
ids.add(rpr.Id);
|
|
|
Test.startTest();
|
if(!Test.isRunningTest()){
|
LogAutoSendSchedule.assignOneMinute();
|
}
|
NFM401Controller.callout(null,null, ids,'R2');
|
Test.stopTest();
|
}
|
|
|
@isTest
|
static void testcallout3(){
|
StaticParameter.EscapeSyncProduct2Trigger = true;
|
StaticParameter.EscapeAccountTrigger = true;
|
// makeTestRepair();
|
List<Repair__c> list0 = [SELECT Id FROM Repair__c];
|
rpr = list0.get(0);
|
// //Q2
|
// qis.Damage_For_Doc_Or_Pat__c = '有';
|
// qis.PAE_Determine__c = 'PAE';
|
// qis.PAE_DetermineAC__c = 'PAE';
|
// qis.RC_inspection_date__c = Date.today();
|
// qis.QIS_Reply_Comment__c ='test';
|
// update qis;
|
List<String> ids = new List<String>();
|
ids.add(rpr.Id);
|
|
|
Test.startTest();
|
if(!Test.isRunningTest()){
|
LogAutoSendSchedule.assignOneMinute();
|
}
|
NFM401Controller.callout(null,null, ids,null);
|
Test.stopTest();
|
}
|
|
@isTest
|
static void testcallout3_1(){
|
StaticParameter.EscapeSyncProduct2Trigger = true;
|
StaticParameter.EscapeAccountTrigger = true;
|
// makeTestRepair();
|
List<Repair__c> list0 = [SELECT Id FROM Repair__c];
|
rpr = list0.get(0);
|
rpr.IISE_confirmed_day__c =Date.today();
|
rpr.IISE_confirmed_person__c = Userinfo.getUserId();
|
rpr.OCSM_RC_CordingDate__c = Date.today();
|
rpr.Return_Without_Repair_Date__c = Date.today();
|
upsert rpr;
|
List<String> ids = new List<String>();
|
ids.add(rpr.Id);
|
|
|
Test.startTest();
|
if(!Test.isRunningTest()){
|
LogAutoSendSchedule.assignOneMinute();
|
}
|
NFM401Controller.callout(null,null, ids,null);
|
|
Test.stopTest();
|
}
|
|
@isTest
|
static void testOtherMethod(){
|
List<Repair__c> list0 = [SELECT Id FROM Repair__c];
|
rpr = list0.get(0);
|
rpr.IISE_confirmed_day__c =Date.today();
|
rpr.IISE_confirmed_person__c = Userinfo.getUserId();
|
rpr.OCSM_RC_CordingDate__c = Date.today();
|
rpr.Return_Without_Repair_Date__c = Date.today();
|
upsert rpr;
|
List<String> ids = new List<String>();
|
ids.add(rpr.Id);
|
|
BatchIF_Log__c rowData = new BatchIF_Log__c();
|
rowData.Log2__c = '';
|
rowData.Log3__c = '';
|
rowData.Type__c = 'NFM401';
|
rowData.Log__c = '{"GeneralDatadummy":[{"SYSTEM_STATUS":"R3","SYSTEM_SOURCEID":"a0J1s000000uDLVEA2"}]}';
|
insert rowData;
|
|
Test.startTest();
|
if(!Test.isRunningTest()){
|
LogAutoSendSchedule.assignOneMinute();
|
}
|
// if (!Test.isRunningTest()) {
|
NFM401Controller.sendToETQ(null,null, ids,'');
|
NFM401Controller.sendToETQ(null,null, null,'');
|
NFM401Controller.callout(null,null, null,null);
|
NFM401Controller.executeAuto(rowData);
|
NFM401Controller.execute('TEST',rowData,null);
|
// }
|
Test.stopTest();
|
}
|
|
@isTest
|
static void testQIS1(){
|
List<QIS_Report__c> list1 = [SELECT Id FROM QIS_Report__c];
|
qis = list1.get(0);
|
// makeTestRepair();
|
List<String> ids = new List<String>();
|
ids.add(qis.Id);
|
|
|
Test.startTest();
|
if(!Test.isRunningTest()){
|
LogAutoSendSchedule.assignOneMinute();
|
}
|
NFM401Controller.sendToETQ(null,null, ids,'Q1');
|
Test.stopTest();
|
}
|
|
@isTest
|
static void testQIS2(){
|
List<QIS_Report__c> list1 = [SELECT Id FROM QIS_Report__c];
|
qis = list1.get(0);
|
qis.Damage_For_Doc_Or_Pat__c = '有';
|
qis.PAE_Determine__c = 'PAE';
|
qis.PAE_DetermineAC__c = 'PAE';
|
update qis;
|
List<String> ids = new List<String>();
|
ids.add(qis.Id);
|
|
Test.startTest();
|
if(!Test.isRunningTest()){
|
LogAutoSendSchedule.assignOneMinute();
|
}
|
NFM401Controller.sendToETQ(null,null, ids,'Q2');
|
Test.stopTest();
|
}
|
|
@isTest
|
static void testQIS3(){
|
List<QIS_Report__c> list1 = [SELECT Id FROM QIS_Report__c];
|
QIS_Report__c qis = list1.get(0);
|
qis.Damage_For_Doc_Or_Pat__c = '无';
|
qis.PAE_Determine__c = 'nonPAE';
|
qis.PAE_DetermineAC__c = 'nonPAE';
|
qis.OCM_judgement__c = '质量问题';
|
qis.QIS_final_judgement__c = '非质量问题';
|
update qis;
|
List<String> ids = new List<String>();
|
ids.add(qis.Id);
|
|
Test.startTest();
|
if(!Test.isRunningTest()){
|
LogAutoSendSchedule.assignOneMinute();
|
}
|
NFM401Controller.sendToETQ(null,null, ids,'Q3');
|
Test.stopTest();
|
}
|
|
|
|
// static testMethod void testMethod2(){
|
|
// List<BatchIF_Transfer__c> transfers = new List<BatchIF_Transfer__c>();
|
// BatchIF_Transfer__c transfer = new BatchIF_Transfer__c();
|
// transfer.Table__c = 'Repair__c';
|
// transfer.Column__c = 'With_Maintenance_Contract__c';
|
// transfer.External_Value__c = '0';
|
// transfers.add(transfer);
|
// transfer.Internal_Value__c = '無';
|
// transfer = new BatchIF_Transfer__c();
|
// transfer.Table__c = 'Repair__c';
|
// transfer.Column__c = 'With_Maintenance_Contract__c';
|
// transfer.External_Value__c = '1';
|
// transfer.Internal_Value__c = '有';
|
// transfers.add(transfer);
|
// insert transfers;
|
|
// //-----------
|
// Profile p = [select Id from Profile where id =:System.Label.ProfileId_SystemAdmin];
|
// // ユーザー作成
|
// User hpOwner = new User(Test_staff__c = true, LastName = 'hp', FirstName = 'owner', Alias = 'hp', CommunityNickname = 'hpOwner', Email = 'olympus_hpowner@sunbridge.com', Username = 'olympus_hpowner@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id);
|
// insert hpOwner;
|
// // 取引先作成
|
// List<RecordType> rectHp = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
|
// if (rectHp.size() == 0) {
|
// return;
|
// }
|
// // layout作成
|
// OFSHospitalLayout__c layout = new OFSHospitalLayout__c();
|
// layout.Name = 'GI-Case';
|
// layout.recordType_devName__c = 'AccountCase_Department_Class_GI';
|
// layout.section1__c = '{"id":"001","title":"# of Room"}';
|
// layout.field1__c = '{"sectionId":"001","label":"OLY Room","parentLabel":"Endoscopy Room","apiNum":"OLY_endscopy_room__c","apiPrice":"OLY_endscopy_room_price__c"}';
|
// layout.field2__c = '{"sectionId":"001","label":"Competitor\'s Room","parentLabel":"Endoscopy Room","apiNum":"Competitor_endoscopy_room__c","apiPrice":"Competitor_endoscopy_room_price__c"}';
|
// insert layout;
|
// //----------------
|
// // テストデータ
|
// Account company = new Account();
|
// // getRecordTypeInfosByDeveloperName()
|
// // company.RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('HP').getRecordTypeId();
|
// company.Name = 'NFM103TestCompany';
|
// // company.ParentId =new Account(Name='name');
|
// Account hp = new Account(RecordTypeId = rectHp[0].Id, Name = 'AccountCaseHistoryTestHp1', OwnerId = hpOwner.Id);
|
// // company.ParentId = new Account(RecordTypeId = rectHp[0].Id, Name = 'AccountCaseHistoryTestHp1', OwnerId = hpOwner.Id);
|
// upsert company;
|
// Account section = new Account();
|
// // section.RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Department_Class_GI').getRecordTypeId();
|
// section.Name = '*';
|
// Account hp1 = new Account(RecordTypeId = rectHp[0].Id, Name = 'AccountCaseHistoryTestHp1', OwnerId = hpOwner.Id);
|
// section.Department_Class_Label__c = '消化科';
|
// section.ParentId = company.Id;
|
// section.Hospital_Department_Class__c = company.Id;
|
// upsert section;
|
|
// StaticParameter.EscapeSyncProduct2Trigger = true;
|
// StaticParameter.EscapeAccountTrigger = true;
|
|
// Account depart = new Account();
|
// //depart.RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Department_GI').getRecordTypeId();
|
// depart.Name = '*';
|
// Account hp2 = new Account(RecordTypeId = rectHp[0].Id, Name = 'AccountCaseHistoryTestHp1', OwnerId = hpOwner.Id);
|
// depart.Department_Name__c = 'NFM103TestDepart';
|
// depart.ParentId = section.Id;
|
// depart.Department_Class__c = section.Id;
|
// depart.Hospital__c = company.Id;
|
// upsert depart;
|
|
// // 再取得
|
// // List<Account> accList = new List<Account>();
|
// // company = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Id = :company.Id];
|
// // accList.add(company);
|
// // section = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Id = :section.Id];
|
// // accList.add(section);
|
// // depart = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Id = :depart.Id];
|
// // accList.add(depart);
|
|
// List<Product2> prdList = new List<Product2>();
|
// Product2 prd1 = new Product2();
|
// prd1.ProductCode_Ext__c = 'NFM103Prd1';
|
// prd1.ProductCode = 'NFM103Prd1';
|
// prd1.Repair_Product_Code__c = 'NFM103Prd1_RP';
|
// prd1.Name = 'NFM103Prd1';
|
// prd1.Manual_Entry__c = false;
|
// prd1.CanRepairAccsessary__c = true;
|
// prdList.add(prd1);
|
// Product2 prd2 = new Product2();
|
// prd2.ProductCode_Ext__c = 'NFM103Prd2';
|
// prd2.ProductCode = 'NFM103Prd2';
|
// prd2.Repair_Product_Code__c = 'NFM103Prd2_RP';
|
// prd2.Name = 'NFM103Prd2';
|
// prd2.Manual_Entry__c = false;
|
// prd2.CanRepairAccsessary__c = true;
|
// prdList.add(prd2);
|
// insert prdList;
|
|
// Asset ast = new Asset();
|
// ast.Name = 'NFM103Ast1';
|
// ast.AccountId = depart.Id;
|
// ast.Department_Class__c = section.Id;
|
// ast.Hospital__c = company.Id;
|
// ast.Product2Id = prd1.Id;
|
// ast.SerialNumber = 'NFM103SerialNumber';
|
// ast.Guarantee_period_for_products__c = Date.today();
|
// ast.InstallDate = Date.today();
|
// insert ast;
|
// ast = [select Id, Name, Product_Serial_No__c, AccountId, Department_Class__c, Department_Class__r.Management_Code_Auto__c, Hospital__c, Product2Id, Product2.ProductCode, Product2.Repair_Product_Code__c, SerialNumber
|
// from Asset
|
// where Id = :ast.Id];
|
// Repair__c rpr = new Repair__c();
|
// rpr.Incharge_Staff__c = Userinfo.getUserId();
|
// rpr.SAPRepairNo__c = 'NFM103Repair1';
|
// rpr.Account__c = depart.Id;
|
// rpr.Department_Class__c = section.Id;
|
// rpr.Hospital__c = company.Id;
|
// rpr.Delivered_Product__c = ast.Id;
|
// rpr.work_location_select__c = '北京办事处';
|
// rpr.SalesOfficeCode_selection__c = '北京';
|
// rpr.Repair_Detail__c = 'test';
|
// insert rpr;
|
|
// rpr=[SELECT Id,Name,Service_Repair_No__c,Hospital__c from Repair__c];
|
// List<String>ls = new List<String>();
|
|
// ls.add(rpr.Id);
|
|
// Test.startTest();
|
// NFM401Controller1.callout(null,null,ls,null);
|
// Test.stopTest();
|
// rpr=[SELECT Id,Name,Service_Repair_No__c,Hospital__c from Repair__c];
|
|
// System.debug('rpr.Hospital__c,Service_Repair_No__c '+rpr.Service_Repair_No__c+' '+rpr.Hospital__c);
|
|
|
|
// }
|
|
|
|
}
|