@IsTest
private class LexLicenceReminderControllerTest {
    @IsTest
    static void testMethod1() {
        User currentUser = [SELECT Id FROM User WHERE Id = :UserInfo.getUserId()];
        LicenceReminderDate__c l = new LicenceReminderDate__c(Name = '180Days', ReminderDays__c = 180);
        insert l;
        Test.startTest();
        System.runAs(currentUser) {
            LexLicenceReminderController.initReminder();
        }
        Test.stopTest();
    }

    @IsTest
    static void testMethod2() {
        Account myAccount1 = new Account();
        Contact core = new Contact();
        User myUser_test = new User();
        User currentUser = [SELECT Id FROM User WHERE Id = :UserInfo.getUserId()];
        LicenceReminderDate__c l = new LicenceReminderDate__c(Name = '180Days', ReminderDays__c = 180);
        insert l;
        System.runAs(currentUser) {
            Profile prof = [SELECT Id FROM Profile WHERE Name = '901_经销商社区普通权限_2重验证(ET)'];
            List<RecordType> rectCo = [SELECT Id FROM RecordType WHERE IsActive = TRUE AND SobjectType = 'Account' AND Name = '販売店'];
            if (rectCo.size() == 0) {
                return;
            }
            List<RecordType> rectHos = [SELECT Id FROM RecordType WHERE IsActive = TRUE AND SobjectType = 'Account' AND Name = '病院'];
            if (rectHos.size() == 0) {
                return;
            }

            myAccount1 = new Account(
                name = 'testaccount001',
                RecordTypeId = rectCo[0].Id,
                Product_Limit_Date__c = 'Test01|2|4,Test02|3|5',
                AgentCode_Ext__c = '9999900'
            );
            insert myAccount1;
            core = new Contact(email = 'jplumber@salesforce.com', firstname = 'Joe', lastname = 'Plumber', accountid = myAccount1.id);
            insert core;
            myUser_test = new User(
                ContactId = core.id,
                Alias = 'newUser',
                Email = 'newuser@testorg.com',
                EmailEncodingKey = 'UTF-8',
                LastName = 'testUser',
                LanguageLocaleKey = 'zh_CN',
                LocaleSidKey = 'zh_CN',
                ProfileId = prof.Id,
                TimeZoneSidKey = 'Asia/Shanghai',
                UserName = 'testUser@testorg.com'
            );
            insert myUser_test;
        }
        Test.startTest();
        System.runAs(myUser_test) {
            LexLicenceReminderController.initReminder();
        }
        Test.stopTest();
    }

    @IsTest
    static void testMethod3() {
        Account myAccount1 = new Account();
        Contact core = new Contact();
        User myUser_test = new User();
        User currentUser = [SELECT Id FROM User WHERE Id = :UserInfo.getUserId()];
        LicenceReminderDate__c l = new LicenceReminderDate__c(Name = '180Days', ReminderDays__c = 180);
        insert l;
        System.runAs(currentUser) {
            Profile prof = [SELECT Id FROM Profile WHERE Name = '901_经销商社区普通权限_2重验证(ET)'];
            List<RecordType> rectCo = [SELECT Id FROM RecordType WHERE IsActive = TRUE AND SobjectType = 'Account' AND Name = '販売店'];
            if (rectCo.size() == 0) {
                return;
            }
            List<RecordType> rectHos = [SELECT Id FROM RecordType WHERE IsActive = TRUE AND SobjectType = 'Account' AND Name = '病院'];
            if (rectHos.size() == 0) {
                return;
            }

            myAccount1 = new Account(
                name = 'testaccount001',
                RecordTypeId = rectCo[0].Id,
                Product_Limit_Date__c = 'Test01|2|4,Test02|3|5',
                AgentCode_Ext__c = '9999900',
                Medical_Equipment_Expiration_Date__c = Date.newInstance(2023, 6, 10)
            );
            insert myAccount1;
            core = new Contact(email = 'jplumber@salesforce.com', firstname = 'Joe', lastname = 'Plumber', accountid = myAccount1.id);
            insert core;
            myUser_test = new User(
                ContactId = core.id,
                Alias = 'newUser',
                Email = 'newuser@testorg.com',
                EmailEncodingKey = 'UTF-8',
                LastName = 'testUser',
                LanguageLocaleKey = 'zh_CN',
                LocaleSidKey = 'zh_CN',
                ProfileId = prof.Id,
                TimeZoneSidKey = 'Asia/Shanghai',
                UserName = 'testUser@testorg.com'
            );
            insert myUser_test;
        }
        Test.startTest();
        System.runAs(myUser_test) {
            LexLicenceReminderController.initReminder();
        }
        Test.stopTest();
    }

    @IsTest
    static void testMethod4() {
        Account myAccount1 = new Account();
        Contact core = new Contact();
        User myUser_test = new User();
        User currentUser = [SELECT Id FROM User WHERE Id = :UserInfo.getUserId()];
        LicenceReminderDate__c l = new LicenceReminderDate__c(Name = '180Days', ReminderDays__c = 180);
        insert l;
        System.runAs(currentUser) {
            Profile prof = [SELECT Id FROM Profile WHERE Name = '901_经销商社区普通权限_2重验证(ET)'];
            List<RecordType> rectCo = [SELECT Id FROM RecordType WHERE IsActive = TRUE AND SobjectType = 'Account' AND Name = '販売店'];
            if (rectCo.size() == 0) {
                return;
            }
            List<RecordType> rectHos = [SELECT Id FROM RecordType WHERE IsActive = TRUE AND SobjectType = 'Account' AND Name = '病院'];
            if (rectHos.size() == 0) {
                return;
            }

            myAccount1 = new Account(
                name = 'testaccount001',
                RecordTypeId = rectCo[0].Id,
                Product_Limit_Date__c = 'Test01|2|4,Test02|3|5',
                AgentCode_Ext__c = '9999900',
                Medical_Equipment_Expiration_Date__c = Date.newInstance(2025, 6, 10)
            );
            insert myAccount1;
            core = new Contact(email = 'jplumber@salesforce.com', firstname = 'Joe', lastname = 'Plumber', accountid = myAccount1.id);
            insert core;
            myUser_test = new User(
                ContactId = core.id,
                Alias = 'newUser',
                Email = 'newuser@testorg.com',
                EmailEncodingKey = 'UTF-8',
                LastName = 'testUser',
                LanguageLocaleKey = 'zh_CN',
                LocaleSidKey = 'zh_CN',
                ProfileId = prof.Id,
                TimeZoneSidKey = 'Asia/Shanghai',
                UserName = 'testUser@testorg.com'
            );
            insert myUser_test;
        }
        Test.startTest();
        System.runAs(myUser_test) {
            LexLicenceReminderController.initReminder();
        }
        Test.stopTest();
    }
}
