Back End Development and APIs Projects - Exercise Tracker TIME OUT on tests

Tell us what’s happening:
I’ve been trying to run the tests. Up to the " Passed: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 everything goes ok, but the rest of the tests all fail and i get time out

When i test myself the values returned by the api are the same as the example project.

Your project link(s)
I apparently cant post more than 2 links (??)
ghub/pnco200/boilerplate-project-exercisetracker

solution: boilerplate-project-exercisetracker - Replit

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36

Challenge: Back End Development and APIs Projects - Exercise Tracker

Link to the challenge:

Your code is throwing this error on the server (it’s scrolling through in the server console while the server restarts during tests):

(node:1872) [MONGOOSE] DeprecationWarning: Mongoose: the `strictQuery` option will be switched back to `false` by default in Mongoose 7. Use `mongoose.set('strictQuery', false);` if you want to prepare for this change. Or use `mongoose.set('strictQuery', true);` to suppress this warning.
(Use `node --trace-deprecation ...` to show where the warning was created)
Your app is listening on port 3000
node:events:491
      throw er; // Unhandled 'error' event
      ^

TypeError: Cannot read properties of null (reading 'username')
    at /home/runner/boilerplate-project-exercisetracker-5/index.js:88:52
    at /home/runner/boilerplate-project-exercisetracker-5/node_modules/mongoose/lib/model.js:5228:18
    at processTicksAndRejections (node:internal/process/task_queues:78:11)
Emitted 'error' event on Function instance at:
    at /home/runner/boilerplate-project-exercisetracker-5/node_modules/mongoose/lib/model.js:5230:15
    at processTicksAndRejections (node:internal/process/task_queues:78:11)
exit status 1

Your problem originates here:

TypeError: Cannot read properties of null (reading 'username')
    at /home/runner/boilerplate-project-exercisetracker-5/index.js:88:52

You should log that value, plus the route inputs and all route responses to watch what is happening around this point during the execution of the route during the tests.

Hi, thanks for answering, i solved that error, when an invalid userId was passed i still tried to acces its variable, however, now the test fails and i dont know why, i get no errors in the console and the response is what its asked.

You’ll need to log all your route names, inputs, and responses to debug. For the GET logs route, I got output like

GET logs
req.body: {}
req.params: {"_id":"63b3152aee77ac153c1cc1f2"}
req.query: {"from":"1989-12-31","to":"1990-01-04"}
{"_id":"63b3152aee77ac153c1cc1f2","username":"fcc_test_16726807461","count":0,"log":[]}

from the last test. The empty log suggests that you’re either not finding the stored exercises or they are not stored. So you really need to log the route names, inputs, and all possible responses from all the routes (at least POST exercise and GET logs) to determine what the code is actually doing.

1 Like

Im sorry if i dont follow well, when you say to log the route you say i should apply some sort of middleware to log every request and response?

Just figured out, i was taking the _id from the body when i should be taking it from the parameters. Thanks for your help!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.