Not passing the tests on URL-Shortener Challenge

Tell us what’s happening:
Hello all, I’m having some trouble with the url-shortener microservice challenge.

I did it on replit, and when I test it, it works perfectly; from both Firefox and Chrome. But for some reason it does not pass the tests.

Here you can have a look at the code

And here the page itself

In particular, I have problem passing test 2 and test 3; any idea what might cause the issue?

Thanks in advance!

Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:97.0) Gecko/20100101 Firefox/97.0

Challenge: URL Shortener Microservice

Link to the challenge:

When I run the FCC test and open up the browser console, I open up the network tab so I can see the http requests being made for the test. This test:

You can POST a URL to /api/shorturl and get a JSON response with original_url and short_url properties. Here’s an example: { original_url : 'https://freeCodeCamp.org', short_url : 1}

Is this call:

This is the payload (body):

That is how FCC expects your microservice to work. This is your response:

Contrast that above payload with what your test page uses:

Do you see the difference?

In your server code here:

app.post("/api/shorturl", function(req, res) {
  const url = req.body.pagina
  // ...

I think you want to rethink that second line.

Your code works. But “working” is not good enough. It has to work the way the requirements want. True, the description does not exactly what the required POST body should be, but we can figure it out with a little detective work. Maybe that is on purpose - trust me, it happens on the job all the time.

3 Likes

Woah, awesome kevin! Your response was super helpful.

At first I tried using the developer console to watch what was happening “behind the scenes” but I was using my own post bodies, so I couldn’t detect anything weird happening.

Your answer helped me to find the error, and after changing the code a little,

From:

app.post("/api/shorturl", function(req, res) {
  const url = req.body.pagina

To:

app.post("/api/shorturl", function(req, res) {
  const url = req.body.url

it now passes flawlessly all the tests and I could complete the challenge.

Thanks a lot! And sorry if my english is a bit weird or I couldn’t make myself clear, it’s not my main language. :woozy_face:

I don’t know if I have to close the topic myself, or have to let an admin do that. But the issue is ressolved, thank you again!

Thanks a lot! And sorry if my english is a bit weird or I couldn’t make myself clear, it’s not my main language.

Your English is fine, and much better than my Spanish. (I have to learn fast - we just moved to Barcelona.)

I don’t know if I have to close the topic myself, or have to let an admin do that.

You don’t have to do anything. We don’t have to “close” them. It’s marked as solved - that’s good enough.

1 Like