Delimiter //
/**
 * @test
 * Test For LOADER_CONTACTS_NORMALIZE_MAP_LANGUAGE_PROVIDED()
 */
Drop Procedure IF EXISTS TEST_LOADER_CONTACTS_MAP_FUNCTION_PROVIDED_OR_NOT//

Create Procedure TEST_LOADER_CONTACTS_MAP_FUNCTION_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_FUNCTIONS');

        Call LOADER_TEST_MOCK_CONTACTS_PUSH(1, 'ID_CONTACTS_NEW = 1, DF_FUNCTIONS_SHORT_LABEL = ''MYFNCT1''', 1, Null);
        Call LOADER_TEST_MOCK_CONTACTS_PUSH(2, 'ID_CONTACTS_NEW = 2, DF_FUNCTIONS_SHORT_LABEL = ''beurk''', 2, Null);
        Call LOADER_TEST_MOCK_CONTACTS_PUSH(3, 'ID_CONTACTS_NEW = 3, DF_FUNCTIONS_SHORT_LABEL = NULL', 3, Null);

        Call LOADER_TEST_MOCK_INFO_PUSH('ID_ADMIN_PARAMS', 1);

        Call LOADER_TEST_MOCK_BUSINESS_PUSH('DF_FUNCTIONS',
                'ID_DF_FUNCTIONS = 1
                , ADMIN_PARAMS_ID_ADMIN_PARAMS = 1
                , DF_FUNCTIONS_SHORT_LABEL = ''MYFNCT1''
                , DF_FUNCTIONS_LABEL = ''My function 1''
                , DF_FUNCTIONS_PREFERENCE = 0'
        );
        Call LOADER_TEST_MOCK_BUSINESS_PUSH('DF_FUNCTIONS',
                'ID_DF_FUNCTIONS = 2
                , ADMIN_PARAMS_ID_ADMIN_PARAMS = 1
                , DF_FUNCTIONS_SHORT_LABEL = ''MYFNCT2''
                , DF_FUNCTIONS_LABEL = ''My function 2''
                , DF_FUNCTIONS_PREFERENCE = 1'
        );

        -- Procedure
        Call LOADER_CONTACTS_NORMALIZE_MAP_FUNCTION_NOT_PROVIDED(1);
        Call LOADER_CONTACTS_NORMALIZE_MAP_FUNCTION_PROVIDED(1);

        -- Assertions
        Call utAssert_eq('Contacts with function short label receive the corresponding function id when it exists'
            , 1
            , (SELECT DF_FUNCTIONS_ID_DF_FUNCTIONS FROM LOADER_CONTACTS WHERE LOADER_STATUS_ID_LOADER_STATUS = 1)
        );
        Call utAssert_eq('Contacts with a function short label that does not exist, receive the preferred function id' 
            , 2
            , (SELECT DF_FUNCTIONS_ID_DF_FUNCTIONS FROM LOADER_CONTACTS WHERE LOADER_STATUS_ID_LOADER_STATUS = 2) 
        );
        Call utAssert_eq('Contacts with a function short label 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 function short label receive the preferred function id' 
            , 2
            , (SELECT DF_FUNCTIONS_ID_DF_FUNCTIONS FROM LOADER_CONTACTS WHERE ID_LOADER_CONTACTS = 3) 
        );

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