Delimiter //
/**
 * test of LOADER_ACCOUNTS_NORMALIZE_MAP_CATEG_PROVIDED()
 * @test
 */
Drop Procedure If Exists TEST_LOADER_ACCOUNTS_MAP_CATEG_PROVIDED//

Create Procedure TEST_LOADER_ACCOUNTS_MAP_CATEG_PROVIDED()
Begin

    Call LOADER_TEST_MOCK_INFO_CLEAN();
    Call LOADER_TEST_MOCK_INFO_PUSH('ID_ENTITIES', 1);


    Call LOADER_TEST_MOCK_ACCOUNTS_CLEAN();
    Call LOADER_TEST_MOCK_BUSINESS_START('DF_ACC_CATEG'); 


    -- //
    -- // Account category is given, admin param has a similary registered category
    Call LOADER_TEST_MOCK_ACCOUNTS_PUSH(1, 'ACCOUNTS_CATEG = ''TESTCODE''', 1, Null); 
    Call LOADER_TEST_MOCK_BUSINESS_PUSH('DF_ACC_CATEG', 
        'ID_DF_ACCOUNTS_CATEGORIES = 1
        , DF_ACC_CATEG_CODE = ''TESTCODE''
        , ENTITIES_ID_ENTITIES = 1'
    ); 

    -- Tested procedure
    Call LOADER_ACCOUNTS_NORMALIZE_MAP_CATEG_PROVIDED(1);
    
    -- Assertions
    Call utAssert_eq('When an account category is given and there is a similar category registered for the admin param, account does not receive any error'
        , 0
        , (SELECT LOADER_STATUS_ERRCOUNT FROM LOADER_STATUS WHERE ID_LOADER_STATUS = 1)
    );
    Call utAssert_eq('When an account category is given and there is similar category registered for the admin param, account receives the id of this registered category'
        , 1
        , (SELECT DF_ACC_CATEG_ID_DF_ACC_CATEG FROM LOADER_ACCOUNTS WHERE ID_LOADER_ACCOUNTS = 1)
    );


    Call LOADER_TEST_MOCK_BUSINESS_CLEAN('DF_ACCOUNTS_TYPES');
    Call LOADER_TEST_MOCK_ACCOUNTS_CLEAN();


    -- //
    -- // Account category is given, but admin param hasn't the similary registered category
    Call LOADER_TEST_MOCK_ACCOUNTS_PUSH(1, 'ACCOUNTS_CATEG = ''WRONGCODE''', 1, Null); 

    -- Tested procedure
    Call LOADER_ACCOUNTS_NORMALIZE_MAP_CATEG_PROVIDED(1);
    
    -- Assertions
    Call utAssert_eq('When an account category is given and it does not exist for the admin param, account receives 1 error'
        , 1
        , (SELECT LOADER_STATUS_ERRCOUNT FROM LOADER_STATUS WHERE ID_LOADER_STATUS = 1)
    );
    Call utAssert_eq('When an account category is given and it does not exist for the admin param, account does not receive any id'
        , Null
        , (SELECT DF_ACC_CATEG_ID_DF_ACC_CATEG FROM LOADER_ACCOUNTS WHERE ID_LOADER_ACCOUNTS = 1)
    );


    Call LOADER_TEST_MOCK_BUSINESS_CLEAN('DF_ACC_CATEG');
    Call LOADER_TEST_MOCK_ACCOUNTS_CLEAN();
    Call LOADER_TEST_MOCK_INFO_CLEAN();

End//
Delimiter ;