URL Shortener: Redirection works, but test 3 does not pass

Hello everyone, here is my code:

When I test the app locally, everything seems to be working, but redirecting test fails. I would greatly appreciate some help on this matter. Sorry in advance if this particular issue was discussed, I didn’t find it.

I haven’t really looked at the code but the GET after the redirect is not the correct URL.

The test does two POSTs and the redirect is supposed to be using the second POST URL but it is the first instead.

POSTs

url: https://boilerplate-project-urlshortener-1.verminatorx.repl.co/?v=1689879983530
url: https://boilerplate-project-urlshortener-1.verminatorx.repl.co/?v=1689879984029

GET

https://boilerplate-project-urlshortener-1.verminatorx.repl.co/?v=1689879983530

Should have been

https://boilerplate-project-urlshortener-1.verminatorx.repl.co/?v=1689879984029

1 Like

Thank you kindly for your feedback. Please excuse me, but I’m still clueless though :sweat_smile:

I would assume your findOne isn’t finding the correct URL. It should be redirecting to the URL from the second POST but it is redirecting to the URL from the initial POST test. Again, I haven’t look at it more and I can’t right now.

1 Like

I looked at the code and it is because of the default you have in the schema. All short properties have the same value.

default: Math.floor((Math.random() * 10000) + 1)

If you want to run a function it has to be an actual function definition. Otherwise, it is just the value at the time of creation.

default: function() {
  return Math.floor((Math.random() * 10000) + 1)
}
1 Like

Oh man, you are my hero. I would not figure it out in thousand years, thank you! Now it works.

1 Like