Delimiter //
/**
 * @test
 * Test For LOADER_CONTACTS_NORMALIZE_CONTACTS_CHECK_ZIP_CODE_MAX_LENGTH()
 */
DROP Procedure IF EXISTS TEST_LOADER_CONTACTS_CHECK_LENGTH//

Create Procedure TEST_LOADER_CONTACTS_CHECK_LENGTH()
Begin

    -- initial dataset
    CALL LOADER_TEST_MOCK_CONTACTS_CLEAN();

    CALL LOADER_TEST_MOCK_CONTACTS_PUSH(1, 'CONTACTS_ADDRESSES_ZIP_CODE = LPAD('''', 12, ''*'')', 1, NULL);
    CALL LOADER_TEST_MOCK_CONTACTS_PUSH(2, 'CONTACTS_ADDRESSES_ZIP_CODE = LPAD('''', 2, ''*'')', 2, NULL);
    CALL LOADER_TEST_MOCK_CONTACTS_PUSH(3, 'CONTACTS_ADDRESSES_ZIP_CODE = LPAD('''', 7, ''*'')', 3, NULL);

    -- Procedure
    CALL LOADER_CONTACTS_CHECK_FIELD_LENGTH(
        'CONTACTS_ADDRESSES_ZIP_CODE'
        , 4
        , 10
        , 1
        , 0
        , null
    );

    -- Assertions
    CALL utAssert_eq('Contacts with too long content are flagged'
        , 1
        , (SELECT LOADER_STATUS_ERRCOUNT FROM LOADER_STATUS WHERE ID_LOADER_STATUS = 1)
    );
    CALL utAssert_eq('Contacts with a too short content are flagged' 
        , 1
        , (SELECT LOADER_STATUS_ERRCOUNT FROM LOADER_STATUS WHERE ID_LOADER_STATUS = 2) 
    );
    CALL utAssert_eq('Contacts with a correct content len are not flagged' 
        , 0
        , (SELECT LOADER_STATUS_ERRCOUNT FROM LOADER_STATUS WHERE ID_LOADER_STATUS = 3) 
    );
    
    -- clean
    CALL LOADER_TEST_MOCK_CONTACTS_CLEAN();

End //
Delimiter ;
