@IsTest
|
public with sharing class NFM402ControllerTest {
|
public NFM402ControllerTest() {
|
|
}
|
|
@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 prdList;
|
|
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 = '销售服务';
|
|
Repair__c rpr = new Repair__c();
|
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.Complaint_Number__c = null;
|
rpr.Incharge_Staff__c = Userinfo.getUserId();
|
rpr.Repair_Detail__c = 'test';
|
rpr.INTERFACE_RECORD_ID__c = 111;
|
insert rpr;
|
|
|
QIS_Report__c qr = new QIS_Report__c(
|
RC__c = UserInfo.getUserId(),
|
Damage_For_Doc_Or_Pat__c = '有',
|
Relation_With_The_Problem__c = '有可能',
|
Report_For_Goz__c = '不知道',
|
Complaint_Number__c = null,
|
QIS_Submit_day__c = Date.Today()
|
);
|
insert qr;
|
}
|
|
@IsTest
|
static void myTest(){
|
Repair__c rep = [SELECT Id,Name,Complaint_Number__c,INTERFACE_RECORD_ID__c from Repair__c];
|
QIS_Report__c qis = [SELECT Id,Name,Complaint_Number__c,INTERFACE_RECORD_ID__c from QIS_Report__c];
|
//------ update by rentongxiao 2020-08-19
|
// Set<Id> ids = new Set<Id>();
|
// ids.add(rep.Id);
|
// ids.add(qis.Id);
|
List<String> ids = new List<String>();
|
ids.add(rep.Id);
|
ids.add(qis.Id);
|
//------ update by rentongxiao 2020-08-19
|
|
|
Test.startTest();
|
Test.setMock(HttpCalloutMock.class,new NFM402HttpCallMock());
|
NFM402Controller.sendRequest(ids);
|
Test.stopTest();
|
|
rep = [SELECT Id,Name,Complaint_Number__c,INTERFACE_RECORD_ID__c from Repair__c];
|
qis = [SELECT Id,Name,Complaint_Number__c,INTERFACE_RECORD_ID__c from QIS_Report__c];
|
System.debug('rep.Complaint_Number__c,INTERFACE_RECORD_ID__c '+rep.Complaint_Number__c+' '+rep.INTERFACE_RECORD_ID__c);
|
System.debug('qis.Complaint_Number__c,INTERFACE_RECORD_ID__c '+qis.Complaint_Number__c+' '+qis.INTERFACE_RECORD_ID__c);
|
}
|
|
}
|