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

Create Procedure TEST_LOADER_CONTACTS_CHECK_ZIP_CODE_MAX_LENGTH()
Begin

    -- initial dataset
    CALL LOADER_TEST_MOCK_CONTACTS_CLEAN();

    CALL LOADER_TEST_MOCK_CONTACTS_PUSH(1, 'CONTACTS_ADDRESSES_ZIP_CODE = LPAD('''', 20, ''*'')', 1, NULL);
    CALL LOADER_TEST_MOCK_CONTACTS_PUSH(2, 'CONTACTS_ADDRESSES_ZIP_CODE = LPAD('''', 10, ''*'')', 2, NULL);
    CALL LOADER_TEST_MOCK_CONTACTS_PUSH(3, 'CONTACTS_ADDRESSES_ZIP_CODE = LPAD('''', 5, ''*'')', 3, NULL);

    -- Procedure
    CALL LOADER_CONTACTS_NORMALIZE_CHECK_ZIP_CODE_MAX_LENGTH(1);

    -- Assertions
    CALL utAssert_eq('Contacts with too long zip code are flagged'
        , 1
        , (SELECT LOADER_STATUS_ERRCOUNT FROM LOADER_STATUS WHERE ID_LOADER_STATUS = 1)
    );
    CALL utAssert_eq('Contacts with the exact zip code lenght are not flagged' 
        , 0
        , (SELECT LOADER_STATUS_ERRCOUNT FROM LOADER_STATUS WHERE ID_LOADER_STATUS = 2) 
    );
    CALL utAssert_eq('Contacts with a valid zip code lenght are not flagged' 
        , 0
        , (SELECT LOADER_STATUS_ERRCOUNT FROM LOADER_STATUS WHERE ID_LOADER_STATUS = 3) 
    );
    
    -- clean
    CALL LOADER_CREATE_TABLE_CONTACTS();

End //
Delimiter ;
