@isTest
private class lexUpdateDateControllerTest {
    public lexUpdateDateControllerTest() {
        
    }
    static testMethod void test1(){
        Account company1 = new Account();
        company1.RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('HP').getRecordTypeId();
        company1.Name = '病院テスト1';
        List<Account> hps = new Account[]{company1};
        insert hps;
          
        List<Account> dc1s = [Select Id, Name, Department_Class_Label__c, Sys_Dept_Name_Change_Chk__c from Account where Parent.Id = :company1.Id and RecordType_DeveloperName__c = 'Department_Class_BF'];
        StaticParameter.EscapeAccountTrigger = true;
        Account depart1 = new Account();
        depart1.RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Department_BF').getRecordTypeId();
        depart1.Name         = '*';
        depart1.Department_Name__c  = '診療科1';
        depart1.ParentId            = dc1s[0].Id;
        depart1.Department_Class__c = dc1s[0].Id;
        depart1.Hospital__c         = company1.Id;
        insert depart1;
        Account depart2 = new Account();
        depart2.RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Department_BF').getRecordTypeId();
        depart2.Name         = '*';
        depart2.Department_Name__c  = '消化科1';
        depart2.ParentId            = dc1s[0].Id;
        depart2.Department_Class__c = dc1s[0].Id;
        depart2.Hospital__c         = company1.Id;
        insert depart2;
        StaticParameter.EscapeSyncProduct2Trigger = true;
        Product2 prd1 = new Product2();
        prd1.ProductCode_Ext__c     = 'HistoryPrd1';
        prd1.ProductCode            = 'HistoryPrd1';
        prd1.Repair_Product_Code__c = 'HistoryPrd1_RP';
        prd1.Name                   = 'HistoryPrd1';
        prd1.Manual_Entry__c        = false;
        prd1.Extend_new_product_gurantee__c = true;
        prd1.Extend_Gurantee_Start__c = Date.today().addDays(-60);
        prd1.Extend_Gurantee_End__c = Date.today().addDays(60);
        insert prd1;

        Oly_TriggerHandler.bypass('AssetHandler');

        Asset ast = new Asset();
        ast.RecordTypeId = Schema.SObjectType.Asset.getRecordTypeInfosByDeveloperName().get('HPAsset').getRecordTypeId();
        ast.SerialNumber = 'abcdefg';
        ast.Name = '测试资产1';
        ast.AccountId              = depart1.Id;
        ast.Department_Class__c    = dc1s[0].Id;
        ast.Hospital__c            = company1.Id;
        ast.Product2Id             = prd1.Id;
        ast.Guarantee_period_for_products__c = Date.today();
        ast.Posting_Date__c = Date.today().addDays(30);
        ast.InstallDate                      = Date.today().addDays(30);
        ast.Manage_type__c = '个体管理';
        ast.FirstApproveDate_old__c = Date.today().addDays(-30);
        ast.Tracing_Information_From__c = true;
        insert ast;

        // Maintenance_Contract__c mContract = createMaintenanceContract(company1, dc1s[0], depart1);
        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.today();
        contract.Hospital__c = company1.Id;
        contract.Department_Class__c = dc1s[0].Id;
        contract.Department__c = depart1.Id;
        contract.Contract_Start_Date__c = Date.today().addDays( -10);   // 10日前
        contract.Contract_End_Date__c = Date.today().addDays( 5);       // 5日後
        contract.SalesOfficeCode_selection__c = '北京RC';
        contract.RecordTypeId = Schema.SObjectType.Maintenance_Contract__c.getRecordTypeInfosByDeveloperName().get('VM_Contract').getRecordTypeId();
        insert contract;
        // lexUpdateDateController con = new lexUpdateDateController();
        lexUpdateDateController.init(contract.Id);
        lexUpdateDateController.userCheck();
    }
}