GET /api/shorturl/undefined - ::ffff:172.18.0.1
{ shortId: 'undefined' }
The shortId being provided is undefined. Since that is obtained from your API by sending in a URL, your API is providing a value of undefined for the test URL for the failing test. So the problem is in your POST route. I forked your project and added more logging of (all) route inputs and (all) responses and the problem is in your URL validation or duplication prevention. Since the test URLs are the same except for a parameter, I believe your validation code is detecting that the protocol/host is the same and flagging the URL as identical to a previous one and hence, not sending a response with a valid shortId to use. You really need to log all route inputs and responses even when debugging one route because the routes interact via the database and the tests use one route to test the other.
You also need to return your responses (return res.json({...}); not res.json({...})).
The issue ended up being the regular expression which validates the url structure, since I used the ‘g’ flag it would concat any string passed to the regex and thus chain both POST commands and thus saying the second url is invalid, removing the flag made it pass all the tests