I am currently finishing the 5th certification (backend and API) projects.
I am working on the 4th Project (Exercise Tracker).
My Program is not able to pass test #10 ( A request to a user’s log GET /api/users/:_id/logs returns a user object with a count property representing the number of exercises that belong to that user.)
When requesting /api/users/:_id/logs , the programs gives exactly the same format that is given by freecodecamp’s proposed app.
But I think the problem is when there are no users with the given id or when there is an error, my result differs with the freecodecamp app one.
I am really not able to detect exactly where the error is.
It’s probably not going to pass since you have to implement the POST routes in their entirety for the tests to work properly. When I add some logging to your POST exercise and GET log routes, I get this output when the tests supply a date:
adding exercise for 6235227e00bcf90453b9be54
exercise: {
"_id": "6235227e00bcf90453b9be54",
"username": "fcc_test_16476494050",
"date": "Mon Jan 01 1990",
"duration": 60,
"description": "test"
}
so the record is created. Without a date (like in most tests), I get:
with no exercise record and an empty log when the test expects a log. On the latter tests with dates provided, I see the log entries.
Logging the date in the POST exercise route confirms this as req.body.date is undefined and not "" as you test in your conditional to set an empty date.
Instead of testing if req.body.date is an empty testing, I have tested it if it is either an empty string or undefined if(req.body.date === "" || req.body.date=== "undefined"), and now I have all the tests that concern the /logs working.