Exercise tracker project - Tests not passing

Tell us what’s happening:
I currently have the following tests failing for the exercise tracker project:

  • I can add an exercise to any user by posting form data userId(_id), description, duration, and optionally date to /api/exercise/add. If no date supplied it will use current date. App will return the user object with the exercise fields added.

  • I can retrieve part of the log of any user by also passing along optional parameters of from & to or limit. (Date format yyyy-mm-dd, limit = int)

I checked the behaviour and cross referenced with the example app from the challenge and everything looks as it should do. I went through the issues in the boilerplate repo for this challenge and haven’t found anything that could potentially be a problem. Any advise would be greatly appreciated! :smile:

Your code so far

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36.

Challenge: Exercise Tracker

Link to the challenge:

1 Like

I moved your question to its own topic because you were asking a question related to your own code for a challenge and were not answering the OP of the other thread. It is always best to create your own thread for you specific question(s). Also, it is advisable to use the Ask for Help button on the challenge, so it auto-populates with your current code and the challenge url.

Thank you.

1 Like

Oh thank you! I will edit the post shortly to provide more info.

Line 76 I had userId: addNewExercise.userId instead of _id: addNewExercise.userId that is why it failed the test. Even though the example live app has it as userId. I think the test needs to change so that it reflects what is being shown. So that has fixed this test:

  • I can add an exercise to any user by posting form data userId(_id), description, duration, and optionally date to /api/exercise/add. If no date supplied it will use current date. App will return the user object with the exercise fields added.

Turns out when I passed userId and data, I had extra parenthesis around userId when I shouldn’t have:

Wrong

const result = await Exercise.find({
     { userId },
      date: {
        $gte: from,
        $lte: to
      }
    })

Correct

const result = await Exercise.find({
      userId,
      date: {
        $gte: from,
        $lte: to
      }
    })