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

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

    Call LOADER_TEST_MOCK_CONTACTS_PUSH(1, 'DF_FORMS_SHORT_FORM = ''STE''', 1, Null);
    Call LOADER_TEST_MOCK_CONTACTS_PUSH(2, 'DF_FORMS_SHORT_FORM = ''XX''', 2, Null);
    Call LOADER_TEST_MOCK_CONTACTS_PUSH(3, 'DF_FORMS_SHORT_FORM = ''''', 3, Null);
    Call LOADER_TEST_MOCK_CONTACTS_PUSH(4, 'DF_FORMS_SHORT_FORM = ''ci''', 3, Null);

    Call LOADER_TEST_MOCK_INFO_PUSH('ID_ADMIN_PARAMS', 1);

    Call LOADER_TEST_MOCK_BUSINESS_PUSH('DF_FORMS'
            , 'ID_DF_FORMS = 1 
            , DF_FORMS_SHORT_FORM = ''STE''
            , `DF_FORMS_FULL_TITLE` = ''société''
            , `DF_FORMS_TRASH` = 0
            , `ADMIN_PARAMS_ID_ADMIN_PARAMS` = 1'
        );
    Call LOADER_TEST_MOCK_BUSINESS_PUSH('DF_FORMS'
            , 'ID_DF_FORMS = 2 
            , DF_FORMS_SHORT_FORM = ''CI''
            , `DF_FORMS_FULL_TITLE` = ''Compagnie''
            , `DF_FORMS_TRASH` = 0
            , `ADMIN_PARAMS_ID_ADMIN_PARAMS` = 1'
        );

    -- Tested procedure
    call LOADER_CONTACTS_NORMALIZE_MAP_SHORTFORM_PROVIDED(1);

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

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

End //
Delimiter ;
