/**
 * This class contains unit tests for validating the behavior of Apex classes
 * and triggers.
 *
 * Unit tests are class methods that verify whether a particular piece
 * of code is working properly. Unit test methods take no arguments,
 * commit no data to the database, and are flagged with the testMethod
 * keyword in the method definition.
 *
 * All test methods in an organization are executed whenever Apex code is deployed
 * to a production organization to confirm correctness, ensure code
 * coverage, and prevent regressions. All Apex classes are
 * required to have at least 75% code coverage in order to be deployed
 * to a production organization. In addition, all triggers must have some code coverage.
 * 
 * The @isTest class annotation indicates this class only contains test
 * methods. Classes defined with the @isTest annotation do not count against
 * the organization size limit for all Apex scripts.
 *
 * See the Apex Language Reference for more information about Testing and Code Coverage.
 */
@isTest
public class ContactToUserTriggerTest {

    //add       wangweipeng                      2021/01/05               start
    public static testMethod void odsToUserToContact() {
        // 省
        Address_Level__c al = new Address_Level__c();
        al.Name = '東京';
        al.Level1_Code__c = 'CN-99';
        al.Level1_Sys_No__c = '999999';
        insert al;
        // 市
        Address_Level2__c al2 = new Address_Level2__c();
        al2.Level1_Code__c = 'CN-99';
        al2.Level1_Sys_No__c = '999999';
        al2.Level1_Name__c = '東京';
        al2.Name = '渋谷区';
        al2.Level2_Code__c = 'CN-9999';
        al2.Level2_Sys_No__c = '9999999';
        al2.Address_Level__c = al.id;
        insert al2;

        // 病院を作る
        Account hospital = new Account();
        hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id;
        hospital.Name = 'test hospital';
        hospital.Is_Active__c = '有効';
        hospital.Attribute_Type__c = '卫生部';
        hospital.Speciality_Type__c = '综合医院';
        hospital.Grade__c = '一级';
        hospital.OCM_Category__c = 'SLTV';
        hospital.Is_Medical__c = '医疗机构';
        hospital.State_Master__c = al.id;
        hospital.City_Master__c = al2.id;
        hospital.Town__c = '东京';
        insert hospital;

        // 戦略科室を得る
        Account[] strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_OTH'];
        // 診療科を作る
        Account dep = new Account();
        dep.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_OTH'].id;
        dep.Name = 'test dep';
        dep.AgentCode_Ext__c = '9999998';
        dep.ParentId = strategicDep[0].Id;
        dep.Department_Class__c = strategicDep[0].Id;
        dep.Hospital__c = hospital.Id;
        insert dep;

        Id rtId = '01210000000Qtky';
        User user = new User();
        user.LastName = 'LastName';
        user.FirstName = 'FirstName';
        user.Alias = 'Alias';
        user.Email = 'olympustest03@sunbridge.com';
        user.Username = 'olympustest03@sunbridge.com';
        user.CommunityNickname = 'CommunityNickname';
        user.IsActive = true;
        user.EmailEncodingKey = 'ISO-2022-JP';
        user.TimeZoneSidKey = 'Asia/Tokyo';
        user.LocaleSidKey = 'ja_JP';
        user.LanguageLocaleKey = 'ja';
        user.ProfileId = System.Label.ProfileId_SystemAdmin;
        user.Job_Category__c = '销售推广';
        user.Province__c = '上海市';
        user.Post__c = '经理';
        user.MobilePhone = '54321';
        user.Mobile_Phone__c = '12345';
        user.Employee_No__c = 'om009238';
        user.Work_Location__c = 'Location';
        user.IsMEBG__c = true;
        user.Use_Start_Date__c = Date.today().addMonths(-6);
        insert user;

        /*Contact contact2 = new Contact();
        contact2.AccountId = dep.Id;
        contact2.FirstName = '責任者';
        contact2.LastName = 'test1经销商';
        contact2.Employee_No_manual__c = 'om009238';
        insert contact2;*/

        ODS__c ods = new ODS__c();
        ods.ALIAS__C = 'om009238';
        ods.BRANCH__C = '';
        ods.CATEGORY3__C = '医疗华北东北营业统括本部';
        ods.CATEGORY4__C = '医疗华北营业本部';
        ods.CATEGORY5__C = '华北营业二部';
        ods.CATEGORY6__C = '河北GIR推广课';
        ods.EMAIL__C = 'chengchao_an@olympus.com.cn';
        ods.EMPLOYEE_NO__C = 'om009238';
        ods.FIRSTNAME__C = 'Chengchao';
        ods.HIRE_DATE__C = Date.today();
        ods.JOB_CATEGORY__C = '技术服务';
        ods.JOB_TYPE__C = '正式-本地员工';
        ods.LASTNAME__C = 'An';
        ods.MOBILEPHONE__C = '13832596948';
        ods.NAME__C = '安承超';
        ods.POST__C = '一般';
        ods.PRODUCT_SPECIALIST_INCHARGE_PRODUCT__C = '';
        ods.SALES_SPECIALITY__C = '';
        ods.UNIQUEID__C = '11181';
        ods.WORK_LOCATION__C = '石家庄';
        ods.Stay_or_not__c = '在职';
        ods.LeaveDate__c = Date.today();

        insert ods;

        ods.LeaveDate__c = Date.today();
        update ods;
    }
    //add       wangweipeng                      2021/01/05               end

    /*public static testMethod void myUnitTest() {
        Id rtId = '01210000000Qtky';
        User user = new User();
        user.LastName = 'LastName';
        user.FirstName = 'FirstName';
        user.Alias = 'Alias';
        user.Email = 'olympustest03@sunbridge.com';
        user.Username = 'olympustest03@sunbridge.com';
        user.CommunityNickname = 'CommunityNickname';
        user.IsActive = true;
        user.EmailEncodingKey = 'ISO-2022-JP';
        user.TimeZoneSidKey = 'Asia/Tokyo';
        user.LocaleSidKey = 'ja_JP';
        user.LanguageLocaleKey = 'ja';
        user.ProfileId = System.Label.ProfileId_SystemAdmin;
        user.Job_Category__c = '销售推广';
        user.Province__c = '上海市';
        user.Post__c = '经理';
        user.MobilePhone = '54321';
        user.Mobile_Phone__c = '12345';
        user.Employee_No__c = '112233';
        user.Work_Location__c = 'Location';
        user.Use_Start_Date__c = Date.today().addMonths(-6);
        
        System.Test.startTest();
        insert user;
        System.Test.stopTest();
        
        Contact con = [select id,RecordTypeId,AccountId,FirstName,LastName,Email,MobilePhone,Employee_No_manual__c,Work_Location_manual__c,Post_picklist__c,Job_Category_picklist__c from Contact where User__c = :user.Id];
        System.assertEquals(rtId, con.RecordTypeId);
        System.assertEquals(System.Label.Olympus_AccountID_Internal_staff, con.AccountId);
        System.assertEquals(user.FirstName, con.FirstName);
        System.assertEquals(user.LastName, con.LastName);
        System.assertEquals(user.Email, con.Email);
        System.assertEquals(user.Mobile_Phone__c, con.MobilePhone);
        System.assertEquals(user.Employee_No__c, con.Employee_No_manual__c);
        System.assertEquals(user.Work_Location__c, con.Work_Location_manual__c);
        System.assertEquals(user.Post__c, con.Post_picklist__c);
        System.assertEquals(user.Job_Category__c, con.Job_Category_picklist__c);
        
        con.LastName = 'lastname2';
        con.FirstName = 'firstname2';
        con.Email = 'olympustest033@sunbridge.com';
        con.MobilePhone = '99999999';
        con.Work_Location_manual__c = 'location2';
        con.Post_picklist__c = '部长';
        con.Job_Category_picklist__c = '销售推广';
        con.Hire_date_text__c = Date.today().addMonths(-6);
        con.Gender_text__c = '男';
        con.dept__c = '服务本部';
        con.Pregnant_Rest__c = true;
        update con;
        
        user = [select Id, FirstName, LastName, Email, Mobile_Phone__c, Employee_No__c, Work_Location__c, post__c, Job_Category__c, Hire_date__c, Gender__c, Dept__c, Pregnant_Rest__c from User where Id = :user.Id];
        System.assertEquals(con.LastName, user.LastName);
        System.assertEquals(con.FirstName, user.FirstName);
        System.assertEquals(con.Email, user.Email);
        System.assertEquals(con.MobilePhone, user.Mobile_Phone__c);
        System.assertEquals(con.Work_Location_manual__c, user.Work_Location__c);
        System.assertEquals(con.Post_picklist__c, user.post__c);
        System.assertEquals(con.Job_Category_picklist__c, user.Job_Category__c);
        System.assertEquals(con.Hire_date_text__c, user.Hire_date__c);
        System.assertEquals(con.Gender_text__c, user.Gender__c);
        System.assertEquals(con.dept__c, user.dept__c);
        System.assertEquals(con.Pregnant_Rest__c, user.Pregnant_Rest__c);
    }*/
}