Delimiter //
/**
 * @test
 * Test For LOADER_ACCOUNTS_NORMALIZE_MAP_CURRENCY_PROVIDED() 
 * and LOADER_ACCOUNTS_NORMALIZE_MAP_CURRENCY_NOT_PROVIDED()
 */
Drop Procedure IF EXISTS TEST_LOADER_ACCOUNTS_MAP_CURRENCY_PROVIDED_OR_NOT//
Create Procedure TEST_LOADER_ACCOUNTS_MAP_CURRENCY_PROVIDED_OR_NOT()
Begin

        -- initial dataset
        Call LOADER_TEST_MOCK_ACCOUNTS_CLEAN();
        Call LOADER_TEST_MOCK_INFO_CLEAN();
        Call LOADER_TEST_MOCK_BUSINESS_CLEAN('DF_CURRENCIES');
        Call LOADER_TEST_MOCK_BUSINESS_CLEAN('ADMIN_PARAMS');

        Call LOADER_TEST_MOCK_ACCOUNTS_PUSH(1, 'ID_ACCOUNTS_NEW = 1, DF_CURRENCIES_CODE = ''EUR''', 1, Null);
        Call LOADER_TEST_MOCK_ACCOUNTS_PUSH(2, 'ID_ACCOUNTS_NEW = 2, DF_CURRENCIES_CODE = ''beurk''', 2, Null);
        Call LOADER_TEST_MOCK_ACCOUNTS_PUSH(3, 'ID_ACCOUNTS_NEW = 3, DF_CURRENCIES_CODE = NULL', 3, Null);

        Call LOADER_TEST_MOCK_INFO_PUSH('ID_ADMIN_PARAMS', 1);

        Call LOADER_TEST_MOCK_BUSINESS_PUSH('DF_CURRENCIES',
                'ID_DF_CURRENCIES = 1
                , DF_CURRENCIES_CODE = ''EUR''
                , DF_CURRENCIES_LABEL = ''Euros'''
        );

        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_ACCOUNTS_NORMALIZE_MAP_CURRENCY_NOT_PROVIDED(1);
        CALL LOADER_ACCOUNTS_NORMALIZE_MAP_CURRENCY_PROVIDED(1);

        -- Assertions
        CALL utAssert_eq('Accounts with a currency code, receive the corresponding currency id when it exists'
            , 1
            , (SELECT DF_CURRENCIES_ID_DF_CURRENCIES FROM LOADER_ACCOUNTS WHERE LOADER_STATUS_ID_LOADER_STATUS = 1)
        );
        CALL utAssert_eq('Accounts with a currency code that does not exist, receive the default currency id' 
            , 1
            , (SELECT DF_CURRENCIES_ID_DF_CURRENCIES FROM LOADER_ACCOUNTS WHERE LOADER_STATUS_ID_LOADER_STATUS = 2) 
        );
        Call utAssert_eq('Accounts with a currency code that does not exist, have a error' 
            , 1
            , (SELECT LOADER_STATUS_ERRCOUNT FROM LOADER_STATUS WHERE ID_LOADER_STATUS = 2) 
        );
        CALL utAssert_eq('Accounts without currency code receive the default currency id' 
            , 1
            , (SELECT DF_CURRENCIES_ID_DF_CURRENCIES FROM LOADER_ACCOUNTS WHERE LOADER_STATUS_ID_LOADER_STATUS = 3) 
        );

        -- clean
        Call LOADER_TEST_MOCK_BUSINESS_CLEAN('ADMIN_PARAMS');
        Call LOADER_TEST_MOCK_BUSINESS_CLEAN('DF_CURRENCIES');
        Call LOADER_TEST_MOCK_INFO_CLEAN();
        Call LOADER_TEST_MOCK_ACCOUNTS_CLEAN();
    
End //
Delimiter ;
