Exercise tracker project not passing but seems to work fine (test timed out?)

Hi there.

I´ve been coding this project and I thought that except for the last test, they all passed. I´ve been confirming this manually, test by test, one by one in my local project, then I decided to publish this on Github and Heroku to be able to confirm with the Freecodecamp what is passing and what is not…

What is my surprise that when I´m checking this, just a few tests pass.

This is what comes up in the tests:

// running tests
You can POST to /api/users/:_id/exercises with form data description, duration, and optionally date. If no date is supplied, the current date will be used. (Test timed out)
The response returned from POST /api/users/:_id/exercises will be the user object with the exercise fields added. (Test timed out)
You can make a GET request to /api/users/:_id/logs to retrieve a full exercise log of any user. (Test timed out)
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. (Test timed out)
A GET request to /api/users/:id/logs will return the user object with a log array of all the exercises added. (Test timed out)
Each item in the log array that is returned from GET /api/users/:id/logs is an object that should have a description, duration, and date properties.
The description property of any object in the log array that is returned from GET /api/users/:id/logs should be a string. (Test timed out)
The duration property of any object in the log array that is returned from GET /api/users/:id/logs should be a number. (Test timed out)
The date property of any object in the log array that is returned from GET /api/users/:id/logs should be a string.. Use the dateString format of the Date API. (Test timed out)
You can add from, to and limit parameters to a GET /api/users/:_id/logs request to retrieve part of the log of any user. from and to are dates in yyyy-mm-dd format. limit is an integer of how many logs to send back. (Test timed out)
// tests completed

After every failed test, there is a time out. Is my code slow? Does the tester not have enough time to check my code? I´m confused with this.

I´m comparing the functionality of both projects, the Freecodecamp and mine and they look the same. I´m not understanding what is wrong. For example, this one works fine but does not pass:

You can POST to /api/users/:_id/exercises with form data description, duration, and optionally date. If no date is supplied, the current date will be used. (Test timed out)
The response returned from POST /api/users/:_id/exercises will be the user object with the exercise fields added. (Test timed out)

My heroku app is:

https://exercise-tracker-21.herokuapp.com/

My code is in here:

Freecodecamp challenge:

By the way, when the automatic test of Freecodecamp runs, my database looks like this, what they have in common is that all the arrays are empty, not sure if that has something to do…:

One thing I noticed that might be causing the problem is there is no error handling, when the user is not found the code returns nothing and only print the error in the console. Maybe try to wrap the code in a try catch and return proper response.

I don´t believe is that because I noticed that the original app from freecodecamp does not handle errors neither.

This is what comes up when a try a random ID in their website:

Cast to ObjectId failed for value “edaewad” at path “_id” for model “Users”

try to return something when the user is not found

I’ve tried to use a “try catch” but it didn’t work. findByIdAndUpdate() is not returning an error when it doesn’t find the id. I wrote and else statement with a json object that says “error: user ID not found” and the test is working very fast now. Used to be veeeery slow and laggy.

Thanks! One of the tests that wasn’t passing is passing now!

I’m still having issues with the other ones even that their functionality is good, but the timing out problem as been solved. I’ll keep looking.