liuyn
2024-03-11 a87f1c3df03078814ee97ad0c8ac200a232419e9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
@isTest
private class buttonMaintenanceTaskCtlTest {
    @TestSetup
    public static void setup() {
     List<RecordType> rectHp = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'];
        if (rectHp.size() == 0) {
            return;
        }
        List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_GI'];
        if (rectDpt.size() == 0) {
            return;
        }
        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', Work_Location__c = '北京', 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;
        // 病院作成
        Account hospital = new Account(RecordTypeId = rectHp[0].Id, Name = 'hp', OwnerId = hpOwner.Id);
        insert hospital;
 
        Account dc = [select Id, Name, RecordType_DeveloperName__c, Account2__c from Account where ParentId = :hospital.Id and RecordType_DeveloperName__c = 'Department_Class_GI'];
        
        // 診療科を作る
        Account dpt1 = new Account(RecordTypeId = rectDpt[0].Id);
        dpt1.Name         = '*';
        dpt1.Department_Name__c  = 'TestDepart1';
        dpt1.ParentId            = dc.Id;
        dpt1.Department_Class__c = dc.Id;
        dpt1.Hospital__c         = hospital.Id;
        insert dpt1;
 
 
        Asset asset = new Asset();
        asset.Name = 'テスト機器';
        asset.AccountId = dpt1.Id;
        asset.Department_Class__c = dc.Id;
        asset.Hospital__c = hospital.Id;
        asset.SerialNumber = 'testserial';
        asset.InstallDate = Date.newInstance(2020, 1, 1);
        asset.Guarantee_period_year__c = 3;
        asset.Posting_Date__c = Date.newInstance(2020, 1, 1);
        insert asset;
 
        Maintenance_Contract__c contract = new Maintenance_Contract__c();
        contract.Name = 'tect contract';
        contract.status__c ='契約';
        contract.Maintenance_Contract_No__c = 'Kami_Contract_No';
        contract.Contract_Conclusion_Date__c = Date.newInstance(2020, 1, 1);
        contract.Hospital__c = hospital.Id;
        contract.Department_Class__c = dc.Id;
        contract.Department__c = dpt1.Id;
        contract.Contract_Start_Date__c = Date.newInstance(2020, 1, 1);
        contract.Contract_End_Date__c = Date.newInstance(2023, 1, 1);
        contract.SalesOfficeCode_selection__c = '北京RC';
        contract.Service_Contract_Staff__c = UserInfo.getUserId();
        contract.RecordTypeId = Schema.SObjectType.Maintenance_Contract__c.getRecordTypeInfosByDeveloperName().get('Maintenance_Contract').getRecordTypeId();
        contract.previousTotalContractAmount__c = 1;
        contract.currentTotalRepairAmount__c = 11111;
        insert contract;
        Maintenance_Contract__c contract1 = new Maintenance_Contract__c();
        contract1.Name = 'tect contract1';
        contract1.status__c ='契約';
        contract1.Maintenance_Contract_No__c = 'Kami_Contract_No1';
        contract1.Contract_Conclusion_Date__c = Date.newInstance(2020, 1, 1);
        contract1.Hospital__c = hospital.Id;
        contract1.Department_Class__c = dc.Id;
        contract1.Department__c = dpt1.Id;
        contract1.Contract_Start_Date__c = Date.newInstance(2020, 1, 1);
        contract1.Contract_End_Date__c = Date.newInstance(2023, 1, 1);
        contract1.SalesOfficeCode_selection__c = '北京RC';
        contract1.Service_Contract_Staff__c = UserInfo.getUserId();
        contract1.RecordTypeId = Schema.SObjectType.Maintenance_Contract__c.getRecordTypeInfosByDeveloperName().get('NewMaintenance_Contract').getRecordTypeId();
        contract1.previousTotalContractAmount__c = 1;
        contract1.currentTotalRepairAmount__c = 11111;
        insert contract1;
 
        Maintenance_Task__c mainTask = new Maintenance_Task__c();
        mainTask.Interval_Start_Date__c = Date.newInstance(2020, 7, 1);
        mainTask.Interval_End_Date__c   = Date.newInstance(2020, 12, 31);
        mainTask.Reference_Consumption_Rate__c = 100;
        mainTask.Maintenance_Consumption_rate__c = 80;
        mainTask.Maintenance_Contract__c = contract.Id;
        mainTask.Is_Generate_Task__c = false;
        insert mainTask;
        Maintenance_Task__c mainTask1 = new Maintenance_Task__c();
        mainTask1.Interval_Start_Date__c = Date.newInstance(2020, 7, 1);
        mainTask1.Interval_End_Date__c   = Date.newInstance(2020, 12, 31);
        mainTask1.Reference_Consumption_Rate__c = 100;
        mainTask1.Maintenance_Consumption_rate__c = 80;
        mainTask1.Maintenance_Contract__c = contract1.Id;
        mainTask1.Is_Generate_Task__c = false;
        insert mainTask1;
        
    }
 
    @isTest
    public static void test_init() {
        List<Maintenance_Task__c> mainTasks = [select id from Maintenance_Task__c limit 1];
        Test.startTest();
        if(mainTasks.size()>0) {
            buttonMaintenanceTaskCtl.init(mainTasks[0].Id);
        }
        
        
        Test.stopTest();
    }
 
    @isTest
    public static void test_selectMaintenanceContract() {
         List<Maintenance_Contract__c> contracts = [select id from Maintenance_Contract__c limit 1];
        Test.startTest();
        if(contracts.size()>0) {
            buttonMaintenanceTaskCtl.selectMaintenanceContract(contracts[0].Id);
        }
        
        Test.stopTest();
    }
}