I’m currently working on the APIs and Microservices certification.
I’ve got stuck in the Exercise tracker challenge, at the 5th point:
I can retrieve a full exercise log of any user by getting /api/exercise/log with a parameter of userId(_id). App will return the user object with added array log and count (total exercise count).
My output is identical to the one present on the FCC project example.
Well, you are setting the count property. So, theoretically, you could be setting it incorrectly. Therefore, it is better the tests make use of the actual expected value.
For this test, a new user is added, and one exercise is added, before the check for the number of exercises is passed. So, you might need to clear your database, and try the test again.
I cleared the whole database and ran the tests again. Still couldn’t pass the 4th user-story. My output is identical to FCC’s so I don’t really know what would be the problem. Maybe the user GETS the log before the exercises are processed in MongoDB Atlas?
I’ve retried the test a couple of times and still doesn’t work.
The output is the same as the model provided by FCC.
The ‘duration’ property is a number, the date is converted to a string using toDateString(), the 'log' property is an array of objects…
I don’t know what would be the cause of this problem.
Anyone has any indication?
Thank you so much!
I was stuck in this project for several weeks.
The problem was, as you’ve pointed out, when the user didn’t specify a date.
The mistake was at my condition:
req.body.date == "" ?
I swapped the ternary operators with an if-else statement (which I am more confident with) and modified the condition:
if(req.body.date)
I think the problem was that my original condition was checking whether or not req.body.date was an empty string, when it should’ve been checking whether or not that value was a falsy in order for it to successfully generate a Data if the user doesn’t specify one.
I will check Postman out after sending this reply.