Tests failing but app works fine

Hi!, I’m doing this url shortener challenge and, despite being working, this two tests aren’t passing:
-When you visit /api/shorturl/<short_url> , you will be redirected to the original URL.
-If you pass an invalid URL that doesn’t follow the valid http://www.example.com format, the JSON response will contain { error: 'invalid url' }

Here you can try the App: https://corty.herokuapp.com/
Here is the code: https://github.com/NachoKai/boilerplate-project-urlshortener/blob/main/server.js

Challenge: URL Shortener Microservice

Link to the challenge:

Welcome, NachoKai.

It seems like the issue is the logic here:

newURL.save((err, url) => {
    if (err) {
      console.error(err);
    } else if (requestedUrl.match(regex)) {
      res.json({
        short_url: url.short_url,
        original_url: url.original_url,
        uuid: url.uuid,
      });
    } else {
      res.json({ error: "Invalid URL" });
    }
  });

If the URL is invalid, it should not be saved, and an error should be responded with.

Also, you have a much more complicated regex than the user story requires:

If you pass an invalid URL that doesn’t follow the valid http://www.example.com format

Here is the test input: ftp:/john-doe.org
Here is your app output:

{"short_url":"https://corty.herokuapp.com/api/shorturl/pAWt13VrF","original_url":"ftp:/john-doe.org","uuid":"pAWt13VrF"}

I hope this helps

1 Like