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
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.