refactor logic to parse queue's URL when using query, add test case