Please extract that to a method and write a test for both cases: with and without baseUrl to ensure it formats correctly.