Delimiter //
/**
 * @test
 * Test For LOADER_CONTACTS_NORMALIZE_MAP_LANGUAGE_PROVIDED() 
 * and LOADER_CONTACTS_NORMALIZE_MAP_LANGUAGE_NOT_PROVIDED()
 */
Drop Procedure IF EXISTS TEST_LOADER_CONTACTS_MAP_LANGUAGE_PROVIDED_OR_NOT//

Create Procedure TEST_LOADER_CONTACTS_MAP_LANGUAGE_PROVIDED_OR_NOT()
Begin

        -- initial dataset
        Call LOADER_TEST_MOCK_CONTACTS_CLEAN();
        Call LOADER_TEST_MOCK_INFO_CLEAN();
        Call LOADER_TEST_MOCK_BUSINESS_CLEAN('DF_LANGUAGES');
        Call LOADER_TEST_MOCK_BUSINESS_CLEAN('ADMIN_PARAMS');

        Call LOADER_TEST_MOCK_CONTACTS_PUSH(1, 'ID_CONTACTS_NEW = 1, DF_LANGUAGES_CODE = ''fr_FR''', 1, Null);
        Call LOADER_TEST_MOCK_CONTACTS_PUSH(2, 'ID_CONTACTS_NEW = 1, DF_LANGUAGES_CODE = ''beurk''', 2, Null);
        Call LOADER_TEST_MOCK_CONTACTS_PUSH(3, 'ID_CONTACTS_NEW = 1, DF_LANGUAGES_CODE = NULL', 3, Null);

        Call LOADER_TEST_MOCK_INFO_PUSH('ID_ADMIN_PARAMS', 1);

        Call LOADER_TEST_MOCK_BUSINESS_PUSH('DF_LANGUAGES',
                'ID_DF_LANGUAGES = 1
                , DF_LANGUAGES_CODE = ''fr_FR''
                , DF_LANGUAGES_LABEL = ''Français'''
        );

        Call LOADER_TEST_MOCK_BUSINESS_PUSH('ADMIN_PARAMS',
                'ID_ADMIN_PARAMS = 1
                , UNIVERS_ID_UNIVERS = 2
                , DF_CURRENCIES_ID_DF_CURRENCIES = 1
                , DF_LANGUAGES_ID_DEF_LANGUAGE = 1
                , DF_COUNTRY_ID_DF_COUNTRY = 1
                , ADMIN_PARAMS_LABEL = ''Test env''
                , ADMIN_TSK_MANUAL_REMMBR = 2'
        );

        -- Procedure
        CALL LOADER_CONTACTS_NORMALIZE_MAP_LANGUAGE_NOT_PROVIDED(1);
        CALL LOADER_CONTACTS_NORMALIZE_MAP_LANGUAGE_PROVIDED(1);

        -- Assertions
        CALL utAssert_eq('Contacts with a language code, receive the corresponding language id when it exists'
            , 1
            , (SELECT DF_LANGUAGES_ID_DF_LANGUAGES FROM LOADER_CONTACTS WHERE LOADER_STATUS_ID_LOADER_STATUS = 1)
        );
        CALL utAssert_eq('Contacts with a language code that does not exist, receive the default language id' 
            , 1
            , (SELECT DF_LANGUAGES_ID_DF_LANGUAGES FROM LOADER_CONTACTS WHERE LOADER_STATUS_ID_LOADER_STATUS = 2) 
        );
        Call utAssert_eq('Contacts with a language code that does not exist, have a warning' 
            , 1
            , (SELECT LOADER_STATUS_WARNCOUNT FROM LOADER_STATUS WHERE ID_LOADER_STATUS = 2) 
        );
        CALL utAssert_eq('Contacts without language code receive the default language id' 
            , 1
            , (SELECT DF_LANGUAGES_ID_DF_LANGUAGES FROM LOADER_CONTACTS WHERE LOADER_STATUS_ID_LOADER_STATUS = 3) 
        );

        -- clean
        Call LOADER_TEST_MOCK_BUSINESS_CLEAN('ADMIN_PARAMS');
        Call LOADER_TEST_MOCK_BUSINESS_CLEAN('DF_LANGUAGES');
        Call LOADER_TEST_MOCK_INFO_CLEAN();
        Call LOADER_TEST_MOCK_CONTACTS_CLEAN();
    
End //
Delimiter ;
