URL shortener project doesn't pass any test

Tell us what’s happening:
I’ve been working on this project for a few days, everything works just fine, but when I submit the project, it doesn’t pass any test. I don’t know why because it meets the project requirements.
I saw the console when I tried to submit the project, and it seems to be receiving two undefined inputs from the freeCodeCamp tests.
Thank you in advance for the help !

Your project link(s)
solution: urlshortener - Replit

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.61 Safari/537.36

Challenge: URL Shortener Microservice

Link to the challenge:

  1. The code was updated at some point but you do not have the latest version. The test is using url and not url_input.

If you change the input element inside the HTML to

<input id="url_input" type="text" name="url" placeholder="https://www.freecodecamp.org/" />

And use req.body.url the two first tests should pass. Or use can restart using the latest version of the project and paste your code into it but that shouldn’t be necessary.

  1. Your isValidUrl function will not throw with the invalid URL used by the test.

ftp:/john-doe.invalidTLD

@lasjorg Which code was updated at some point? The boilerplate?

The input's name attribute value in /views/index.html has not been updated in the boilerplate from the following since it was first created in 2017.

<input id="url_input" type="text" name="url" value="https://www.freecodecamp.com">

I didn’t actually look at the PR to check what was changed I just assumed the camper hadn’t changed the name attribute as I can see no reason why they would do so. But I guess the PR I saw only changed the action value for the POST. But I can see how one might assume the form is directly used by the test (filled out and submitted).

Anyway, the fix is the same correct the input element and use the correct property.

Maybe the user changed it to name="input_url" for some other reason.

Clearly, I just don’t really understand why. I guess it doesn’t matter, the code just needs to match the test.

This was the solution ! All test have passed successfully.
Here was the problems:

  • At some point, I changed the name attribute of the input from “url” to “url_input”, this caused the tests to fail. Restoring it to name="url" fixed the problem
  • For the validation of the url in the third test, which was ftp:/john-doe.invalidTLD, I used the valid-url package and with this line of code it passed:
if (!validUrl.isWebUri(url)) return res.json({ error: 'invalid url' });

Thanks a lot for the help ! I was really stuck with this project for days, I can finally move on ! Have a great day :sunny: