Why do URL Shortener Microservice Tests Fail?

Tell us what’s happening:
Hello. I’m trying to solve the URL Shortener Microservice project, and it is failing the automated tests, but I cannot figure out why, as it correct actions are performed when I test in my browser.

Specifically, it fails the second test: “POST a URL to /api/shorturl and get a JSON response with original_url and short_url properties.”, and the third test: “When you visit /api/shorturl/<short_url> , you will be redirected to the original URL.”

Your project link(s)

here is my solution: https://replit.com/@jordash/boilerplate-project-urlshortener

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:89.0) Gecko/20100101 Firefox/89.0

Challenge: URL Shortener Microservice

Link to the challenge:

Welcome there,

I suggest you console.log the first argument you are passing into dns.lookup, then look at the documentation for dns.lookup, and look at a few examples if need be.

Otherwise, make use of the browser devtools to see the network requests made by the freeCodeCamp tests.

Hope this helps

Thank you @Sky020, I’ll give that a try. As far as I can tell I am using dns.lookup correctly, and the domain name (passed in as the first parameter) is appearing in the console as expected.

I would really double check that. If you get errors from valid addresses, it is because you are not passing in the correct argument. This is what I see:

##dns.lookup: org_url: boilerplate-project-urlshortener-1.sky020.repl.co/?v=1623426844494 ##

Click for hint:

dns.lookup expects only the hostname as the first argument - nothing else. Search what a hostname consists of, if you are unsure.

Hope this helps

Ah, understood! I rechecked and adjusted the dns.lookup argument to provide just the hostname (without query string) as it had allowed previously. The console is now showing only what appear to be valid hostnames: e.g. ‘boilerplate-project-urlshortener.jordash.repl.co’ Do you see anything else that isn’t correct? It’s still failing the checks.

In the browser network tab, I see this as your app’s response:

original_url: "boilerplate-project-urlshortener.jordash.repl.co"
short_url: "29"

Can you see the issue here?

The original URL should be https://boilerplate-project-urlshortener.jordash.repl.co/?v=16234415579

Hope this helps

Yes, I finally got it!! I was stripping off the protocol to pass to the dns.lookup, but not adding it back before returning the original_url in the json response. Thank you so much for your hints, it is now passing the tests!