Hello everyone!
It is the last certification i need to get and my 4,5,6 tests keep failing.
I have already looked into similar cases in forums, i tried changing bits and pieces
in my code, i changed _id with userId and vica versa in all places.
At the moment I’m at 4 hours refactoring even though everything is working as intended (or at least that’s what i think ).
I could really use some help! Thanks for your time in advance!
The route path for exercise logs which you’ve defined is /api/exercise/users/log is incorrect. It should be /api/exercise/log.
And for the fourth test, the response should contain _id property which should be equal to the user’s ID.
So you just need to edit line 135 from userId: user._id to this _id: user._id
Changing userId to _id is not intended and is a bug. You just need to do it as is for the sake of passing the test here.
The bug was at the json after adding the exercise, the description was returning String where it should be returning Number, and even though I had type set to Number at input field and model, it was still giving back a string. Forced it here to get the correct output:
app.post("/api/exercise/add", (req, res) => {
let { userId, description, duration, date } = req.body;
date = date ? new Date(date) : new Date()
duration = Number(duration)
...
..
.
}
Or at least that is what worked for me, I hope they fix this in the future!