Exercise Tracker tests are bugged?

Tell us what’s happening:
Describe your issue in detail here.

https://fringe-ambiguous-growth.glitch.me/

So… I really don’y understand why the adding exercises test is failing.

My output looks IDENTICAL to the example app provided by the FCC team, both with and without date provided (I mean even if you enter a date or one is added automatically - it all works fine and exactly like the example app).

What am I missing?
I’ve been stuck on this exercise for weeks now and I have no idea what I’m doing wrong.

Your code so far

Your browser information:

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

Challenge: Exercise Tracker

Link to the challenge:

If the tests were buggy the example project wouldn’t pass them.

The tests are timing out which usually means no response is received. For the POST to /api/users/:_id/exercises I would check the response, if I look in the browser console when submitting I don’t see a response coming back.

For the rest of the failing tests, I do not see a /api/users/:_id/logs route in your code.

You can look at the tests to see what is being sent and the expected return values.

Hi,

For me the tests are not timing out, just failing.
The reason the console is clear is because I’m not logging anything to it, just returning a json (res.json) – and it looks IDENTICAL to the example app provided in the course details.

For the rest of the tests - that’s because I haven’t implemented any code for them, I’m stuck the the exercise-adding (or I mean it looks to me like the website and tests are stuck rather than me, because as I’ve said, my code seems to work since the response looks identical and the database records looks fine too, and no errors are thrown anywhere).

EDIT: Glitch :・゚✧
This is the link to the code if you want to check it out

Do you not see (Test timed out) at the end of the test messages?

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. The response returned will be the user object with the exercise fields added. (Test timed out)

I’m not talking about console logs. I’m talking about the network tab and the response.

I just took a quick glance but I think you’ve forgotten to pass in the returned document here:

newUser.save().then(() => res.json(newUser));

Should be something like:

newUser.save().then(savedUser => res.json(savedUser));

Might explain why the user gets saved to the DB, but the response times out.

newUser is defined outside of this function and the whole user creation function works and the test passes.

Technically the only test I have a problem with is the exercise creation one (test #4 if you include the ‘provide your own solution’ one).
Which seems to work too, but the test is failing for some reason.

I just edited some code, tried to return the whole user object after inserting an exercise (that’s what the test description says but not what the example app is doing)
Anyway - bot methods works completely fine but the test is still failing.

I noticed that if I remove the regex that validates that the id passed is a valid id and i run the tests, I get and error saying something like “can’t convert string ‘test’ to ObjectId” or something like that.
I’m guessing this is just FCC checking that I have some input validation in place?

This may or may not be related to the problem, but one discrepancy I noticed is that you’re returning a newUser object when creating a new user. The requirement states that you return an object that consists of two items: username and _id.

This is what I did

 } else { //add new user
        const user = new User(
                      {username: req.body.username,
                      exercises: [ ]})

        user.save((err, data) => {
          if (err) return console.log(err)

          res.json({
            username: data.username,
            _id: data._id
          })
        })
      }

I think you’re right but it’s really not the point, the user creation works fine and the test is passing.

My problem is with the exercise creation, which also works fine, but the test is failing.

So I took a deeper look and good news is that your problem is solved, you were right that your output was exactly the same as the example’s output - unless the input was invalid.

At some points, the tests hit a route /api/users/:_id/exercises where the id is valid, but they enter an invalid string (‘test’) inside the :_id input field. Your code extracts the user id from that input field and not from the route, like this:

const id = req.params._id;

If you change that one line, the tests pass.


EDIT: That wasn’t quite correct, the tests don’t actually use your HTML form, they send this as request body:

body: `description=${expected.description}&duration=${expected.duration}&date=1990-01-01`

That’s why I thought they entered a string 'test' into the input field. It was the description text instead. That’s also why it was hard to detect for you, since in your own tests, you always used the HTML form.

But anyway, assuming that _id would always be the first item in the array that you get from Object.values() seems like a bug invitation, given that objects don’t guarantee a certain order (as far as I know).

1 Like

Thank you so much!

I’m pretty sure objects does guarantee a certain order, but it really doesn’t matter.
I was wrong and I shouldn’t have done it that way, thanks for explaining me my mistake :slight_smile:

According to spec (see this article for example) the order is not guaranteed, so whenever you deal with an object and you know the key you’re looking for, it’s better to get the value through req.body._id instead of Object.values(req.body)[0], but anyway, glad it could be solved, I enjoyed figuring it out.

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