Help! Issues with the test for the Exercise Tracker project?

Hey there.

I´ve done my exercise tracker project. I know it works fine, it does all the things that says in the stories. I´ve tested them one by one, comparing mine to the one as example (the one from Freecodecamp).

I think the stories are not specific enough. My code does what is supposed to do, but the test fails and does not say why.

So… I ended up looking projects from people that have the back end certificate and checked if their projects would pass (without intention of submitting it, as is not my work anyways) because I´ve started to be quite sceptic with all this. And I can see that their projects are functional, they have the certificate BUT the test does not pass? How is that possible? Does not that mean that maybe the tests are not working as they are supposed to work?

How can I fix my code to pass the test when I know for a fact that is working? When I know that is doing all the things that the stories ask me to do? When I’m not finding errors?

I´m starting to feel defeated with this.

My code is this one:

And my app is in here:

If anyone can share a more specific requirement to past the tests, would be great.

The completed projects do get out of step with the requirements as they are updated. I doubt all of my originals still pass, but they did.

Unfortunately, while they could be more descriptive in why they fail, these tests are not broken. The only way to find the problem is to debug. There are two things you absolutely have to do to start debugging:

  1. Log all the route inputs with something like:
  console.log('in exercise add');
  console.log(`req.body:  ${JSON.stringify(req.body)}`);
  console.log(`req.params:  ${JSON.stringify(req.params)}`);
  console.log(`req.query:  ${JSON.stringify(req.query)}`);
  1. Log all the route outputs with:
      error: "ID not found",
    return res.json({
      error: "ID not found",

Notice also the return on the res.json() or whatever response. You really want to explicitly return those responses. I made these modifications to your /api/users/:_id/exercises route and produced this output:

in exercise add
req.body:  {"description":"test","duration":"60","date":"1990-01-01"}
req.params:  {"_id":"617c96422aa3620193cd4f7d"}
req.query:  {}
{ error: 'ID not found' }

So the route can’t find the provided ID. The code is looking for

    _id: req.body[":_id"],

which is looking in req.body and not req.params and hence, not finding it. This is probably causing most of the failures. Debug the rest of the failing routes in similar fashion.

In defense of the tests, there really are so many things that can cause a test to fail that it is really hard to have the test specify in any great detail why it failed.

Thanks so much, @jeremy.a.gray!

It seems that yes, the tests were testing via req.params and not req.body (which made sense to me as one needs to put their ID to manually add exercises), but I had no way to know that.

This has “fixed” almost all the requirements to pass the tests.

By the way, is there a way to see locally the gets and posts the tests are performing on heroku? I would like to see the console.logs while their tests are executing.