URL Shortener project for Microservices: Tests fail, but manual provision succeeds

Tell us what’s happening:
When I click ‘I’ve completed this challenge’ I see that there’s a failure for the test:
When you visit /api/shorturl/<short_url>, you will be redirected to the original URL.

However, I’m logging the shortenedUrlsStorage variable, and when I past into the /api/shorturl/<short_url> using that, it correctly redirects me. This is regardless of whether or not the key appears to be a string in the output. This also is confusing since some of the keys don’t appear to be strings but still redirect when pasted into /api/shorturl/<short_url>

When I use curl to pass the url, I get a working redirect shorturl back:

:~> curl -d "url=www.google.com" -X POST https://boilerplate-project-urlshortener.seandoe.repl.co/api/shorturl

The resulting shortenedUrlsStorage object after running the previous curl of the URL matching google is:

  '8d23e433cc3d215b': 'https://boilerplate-project-urlshortener.seandoe.repl.co/?v=1642180460583',
  cca0d1c3f9fa222b: 'https://boilerplate-project-urlshortener.seandoe.repl.co/?v=1642180460912',
  bc7ab377c022c12a: 'www.google.com'

Testing against one of those shortUrls, I’m seeing a successful redirect as well:

:~> curl -LI https://boilerplate-project-urlshortener.seandoe.repl.co/api/shorturl/cca0d1c3f9fa222b
HTTP/2 302 
access-control-allow-origin: *
content-type: text/plain; charset=utf-8
date: Fri, 14 Jan 2022 17:17:45 GMT
expect-ct: max-age=2592000, report-uri="https://sentry.repl.it/api/10/security/?sentry_key=615192fd532445bfbbbe966cd7131791"
location: https://boilerplate-project-urlshortener.seandoe.repl.co/?v=1642180460912
replit-cluster: global
strict-transport-security: max-age=4250216; includeSubDomains
vary: Accept
x-powered-by: Express
content-length: 95

HTTP/2 200 
accept-ranges: bytes
access-control-allow-origin: *
cache-control: public, max-age=0
content-type: text/html; charset=UTF-8
date: Fri, 14 Jan 2022 17:17:45 GMT
etag: W/"381-17e32847bc7"
expect-ct: max-age=2592000, report-uri="https://sentry.repl.it/api/10/security/?sentry_key=615192fd532445bfbbbe966cd7131791"
last-modified: Fri, 07 Jan 2022 03:10:50 GMT
replit-cluster: global
strict-transport-security: max-age=4250216; includeSubDomains
x-powered-by: Express
content-length: 897

Happy to provide any additional information required.

Your project link(s)

solution: https://replit.com/@seandoe/boilerplate-project-urlshortener

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64; rv:92.0) Gecko/20100101 Firefox/92.0

Challenge: URL Shortener Microservice

Link to the challenge:

This is the problem in the POST route:

  const successResponse = await promiseResJson(res.json({ original_url: providedUrl, short_url: `https://boilerplate-project-urlshortener.seandoe.repl.co/api/shorturl/${randomUrl}`}));

The response has to look like this (example from the test page):

{ original_url : 'https://freeCodeCamp.org', short_url : 1}

You don’t need to return a valid URL as the short_url; the client is expected to use the returned value to construct a new URL using your API.

Run the tests and look in the browser console and you’ll see the errors.

1 Like

Once again, you’ve helped me get unstuck.
Thank you so much for taking the time.