Delimiter //
/**
 * @test
 * Test For LOADER_REFDATA_NORMALIZE_ENTITIES_REF_SEQUENCE_RANGE()
 */
DROP Procedure IF EXISTS TEST_LOADER_REFDATA_NORMALIZE_ENT_REF_SEQ_RANGE//
Create Procedure TEST_LOADER_REFDATA_NORMALIZE_ENT_REF_SEQ_RANGE()
Begin
    
    -- Context
    Call LOADER_TEST_MOCK_BUSINESS_CLEAN('ENTITIES_REF_TYPES');
    Call LOADER_TEST_MOCK_BUSINESS_PUSH('ENTITIES_REF_TYPES', 
            'ID_ENTITIES_REF_TYPES = 1
            , ENTITIES_REF_TYPES_MAX_SEQ = 20
            , ENTITIES_REF_TYPES_CODE = ''ACCOUNTS''
            '
    );

    -- initial dataset
    CALL LOADER_REFDATA_CLEAN();

    CALL LOADER_REFDATA_PUSH(1, 'ENTITIES_REF_SEQUENCE = 1 ', 1, NULL);
    CALL LOADER_REFDATA_PUSH(2, 'ENTITIES_REF_SEQUENCE = 50 ', 2, NULL);

     -- Procedure
    CALL LOADER_REFDATA_NORMALIZE_ENTITIES_REF_SEQUENCE_RANGE(1);

    -- Assertions
    CALL utAssert_eq('data with incorrect sequence value are flagged' 
        , 1
        , (SELECT LOADER_STATUS_ERRCOUNT FROM LOADER_STATUS WHERE ID_LOADER_STATUS = 2) 
    );
    CALL utAssert_eq('data with correct sequence value are not flagged' 
        , 0
        , (SELECT LOADER_STATUS_ERRCOUNT FROM LOADER_STATUS WHERE ID_LOADER_STATUS = 1) 
    );

    -- clean
    CALL LOADER_REFDATA_CLEAN();
    Call LOADER_TEST_MOCK_BUSINESS_CLEAN('ENTITIES_REF_TYPES');
    Call LOADER_TEST_MOCK_INFO_CLEAN();
End //
Delimiter ;
