Delimiter //
/**
 * test of LOADER_ACCOUNTS_NORMALIZE_MAP_CATEG_NOT_PROVIDED()
 * @test
 */
Drop Procedure If Exists TEST_LOADER_ACCOUNTS_MAP_CATEG_NOT_PROVIDED//

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


    -- //
    -- // Entity has no default categ
    Call LOADER_TEST_MOCK_ACCOUNTS_PUSH(1, 'ID_ACCOUNTS_NEW = 1, ACCOUNTS_CATEG = ''''', 1, Null);

    -- Tested procedure
    Call LOADER_ACCOUNTS_NORMALIZE_MAP_CATEG_NOT_PROVIDED(1);
    
    -- Assertions
    Call utAssert_eq('Account receives an error when no account category is given and there is no default category registered for the entity'
        , 1
        , (SELECT LOADER_STATUS_ERRCOUNT FROM LOADER_STATUS WHERE ID_LOADER_STATUS = 1)
    );
    Call utAssert_eq('Account does not receive any category id when no account category is given and there is no default category registered for the entity'
        , 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();
   

    -- //
    -- // Entity has a default categ
    Call LOADER_TEST_MOCK_BUSINESS_PUSH('DF_ACC_CATEG', Concat(
        'ID_DF_ACCOUNTS_CATEGORIES = 1
        , DF_ACC_CATEG_CODE = ''DOVALID''
        , ENTITIES_ID_ENTITIES = 1'
    )); 
    Call LOADER_TEST_MOCK_ACCOUNTS_PUSH(1, 'ID_ACCOUNTS_NEW = 1, ACCOUNTS_TYPE = ''''', 1, Null); 

    -- Tested procedure
    Call LOADER_ACCOUNTS_NORMALIZE_MAP_CATEG_NOT_PROVIDED(1);
    
    -- Assertions
    Call utAssert_eq('Account does not receive any error when no account category is given but there is a default category registered for the entity'
        , 0
        , (SELECT LOADER_STATUS_ERRCOUNT FROM LOADER_STATUS WHERE ID_LOADER_STATUS = 1)
    );
    Call utAssert_eq('Account receives the default category id when no account category is given but there is a default category registered for the entity'
        , 1
        , (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 ;