@isTest
|
private class GetMaintenanceContractAssetBatchTest {
|
static Asset createAsset(String input, String accountid, String dcId, String hpId, String serialNo, String prId) {
|
Asset asset = new Asset();
|
asset.Name = input;
|
asset.AccountId = accountid;
|
asset.Department_Class__c = dcId;
|
asset.Hospital__c = hpId;
|
asset.SerialNumber = serialNo;
|
asset.Product2Id = prId;
|
insert asset;
|
return asset;
|
}
|
|
static testMethod void testMethod1() {
|
Account hospital = new Account();
|
hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id;
|
hospital.Name = 'test hospital';
|
insert hospital;
|
|
// 戦略科室を得る
|
List<Account> strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_GI'];
|
|
// 診療科を作る
|
Account dep = new Account();
|
dep.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_GI'].id;
|
dep.Name = 'test dep';
|
dep.ParentId = strategicDep[0].Id;
|
dep.Department_Class__c = strategicDep[0].Id;
|
dep.Hospital__c = hospital.Id;
|
insert dep;
|
|
// 製品を作る
|
Product2 productA = new Product2( Name='テスト商品', Maintenance_Price_Year__c = 12000, Manual_Entry__c = false);
|
insert productA;
|
|
|
// 納入機器を作成する
|
Asset asset01 = createAsset('asset:01', dep.Id, strategicDep[0].Id, hospital.Id, '00001', productA.Id);
|
|
// 维修合同を作成する
|
Maintenance_Contract__c contract = new Maintenance_Contract__c();
|
contract.Name = 'tect contract';
|
contract.Hospital__c = hospital.Id;
|
contract.Department_Class__c = strategicDep[0].Id;
|
contract.Department__c = dep.Id;
|
contract.Contract_End_Date__c = Date.today();
|
contract.Status__c= '契約';
|
contract.Not_Upper_limit_reason__c = 'test';
|
contract.Maintenance_Contract_No__c = 'contact1';
|
contract.RecordTypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Maintenance_Contract__c' and DeveloperName = 'NewMaintenance_Contract'].id;
|
insert contract;
|
|
// 维修合同保有设备
|
Maintenance_Contract_Asset__c mca = new Maintenance_Contract_Asset__c();
|
mca.Asset__c = asset01.Id;
|
mca.Maintenance_Contract__c = contract.Id;
|
insert mca;
|
|
// List<Maintenance_Contract_Asset__c> mcalist = [select id,Maintenance_Contract__r.Contract_End_Date__c,Asset__c,Maintenance_Contract__r.recordtype.name,Maintenance_Contract__r.Status__c,Estimate_List_Price_All__c from Maintenance_Contract_Asset__c];
|
// String str = mcalist[0].Maintenance_Contract__r.recordtype.name + ','+ mcalist[0].Maintenance_Contract__r.Status__c + ',' + mcalist[0].Estimate_List_Price_All__c;
|
|
// List<Maintenance_Contract_Asset__c> mcalist1 = [select id,Maintenance_Contract__r.Contract_End_Date__c,Asset__c from Maintenance_Contract_Asset__c where ( Maintenance_Contract__r.recordtype.name = '服务合同' or Maintenance_Contract__r.recordtype.name = '维修合同') and (Maintenance_Contract__r.Status__c = '契約' or Maintenance_Contract__r.Status__c = '契約満了') and Estimate_List_Price_All__c = null];
|
// System.assertEquals('1', str);
|
Database.executeBatch(new GetMaintenanceContractAssetBatch(), 100);
|
}
|
}
|