Delimiter //
/**
 * @test
 * Test For LOADER_CONTACTS_NORMALIZE_MAP_TITLE_PROVIDED()
 */
Drop Procedure IF EXISTS TEST_LOADER_CONTACTS_SHORT_TITLE_PROVIDED_OR_NOT//

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

    Call LOADER_TEST_MOCK_CONTACTS_PUSH(1, 'DF_TITLES_SHORT_TITLE = ''M.''', 1, Null);
    Call LOADER_TEST_MOCK_CONTACTS_PUSH(2, 'DF_TITLES_SHORT_TITLE = ''XX''', 2, Null);
    Call LOADER_TEST_MOCK_CONTACTS_PUSH(3, 'DF_TITLES_SHORT_TITLE = ''''', 3, Null);
    Call LOADER_TEST_MOCK_CONTACTS_PUSH(4, 'DF_TITLES_SHORT_TITLE = ''Mrs''', 3, Null);

    Call LOADER_TEST_MOCK_INFO_PUSH('ID_ADMIN_PARAMS', 1);
    Call LOADER_TEST_MOCK_INFO_PUSH('ID_LANGUAGES', 1);

    Call LOADER_TEST_MOCK_BUSINESS_PUSH('DF_TITLES', 
            'ID_DF_TITLES = 1
            , ADMIN_ID_ADMIN = 1
            , DF_TITLES_SHORT_TITLE = ''M.''
            , DF_TITLES_TYPE = 0
            , DF_TITLES_TRASH = 0
            , DF_LANGUAGES_ID_DF_LANGUAGES = 1'
    );
    Call LOADER_TEST_MOCK_BUSINESS_PUSH('DF_TITLES', 
            'ID_DF_TITLES = 2
            , ADMIN_ID_ADMIN = 1
            , DF_TITLES_SHORT_TITLE = ''MRS''
            , DF_TITLES_TYPE = 0
            , DF_TITLES_TRASH = 0
            , DF_LANGUAGES_ID_DF_LANGUAGES = 1'
    );

    -- Tested procedure
    call LOADER_CONTACTS_NORMALIZE_MAP_TITLE_PROVIDED(1);

    -- Assertions
    CALL utAssert_eq('Contacts with provided valid title receive its id'
        , 1
        , (SELECT DF_TITLES_ID_DF_TITLES  FROM LOADER_CONTACTS WHERE ID_LOADER_CONTACTS = 1)
    );
    CALL utAssert_eq('Contacts with provided invalid title dont receive its id'
        , NULL
        , (SELECT DF_TITLES_ID_DF_TITLES  FROM LOADER_CONTACTS WHERE ID_LOADER_CONTACTS = 2)
    );
    CALL utAssert_eq('Contacts with provided invalid title receive a warning'
        , 1
        , (SELECT LOADER_STATUS_WARNCOUNT FROM LOADER_STATUS WHERE ID_LOADER_STATUS = 2)
    );
    CALL utAssert_eq('Contacts without provided title are not changed'
        , NULL
        , (SELECT DF_TITLES_ID_DF_TITLES  FROM LOADER_CONTACTS WHERE ID_LOADER_CONTACTS = 3)
    );
    CALL utAssert_eq('Contacts with provided case insensitive valid title receive its id'
        , 2
        , (SELECT DF_TITLES_ID_DF_TITLES  FROM LOADER_CONTACTS WHERE ID_LOADER_CONTACTS = 4)
    );

    -- clean
    Call LOADER_TEST_MOCK_BUSINESS_CLEAN('DF_TITLES');
    Call LOADER_TEST_MOCK_INFO_CLEAN();
    Call LOADER_TEST_MOCK_CONTACTS_CLEAN();

End //
Delimiter ;
