Exercise Tracker test times out

I really can’t tell why the 5th test (“I can retrieve a full exercise log of any user by getting /api/exercise/log with a parameter of userId(_id). App will return the user object with added array log and count (total exercise count).”) times out. I tried different variations, but can’t get it to work. Please help!

Your code so far

Your browser information:

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

Challenge: Exercise Tracker

Link to the challenge:

Can you post that part of your code

Of course. Sorry

app.get('/api/exercise/log', (req, res) => {
  const userId = req.query.userId;
  const from = req.query.from && Date.parse(req.query.from);
  const to = req.query.to && Date.parse(req.query.to);
  const limit = req.query.limit;
  
  if (!userId) return res.type('txt').send("Unknown userId");
  
  User.findById(userId, (err, user) => {
    if (err) return err;
    
    if (!user) return res.type('txt').send("User not found");
    
    const log = user.exercises.filter(exercise => {
      const date = Date.parse(exercise.date);
      
      if (from && to) {
        return date >= from && date <= to; 
      } else if (!from && to) {
        return date <= to;
      } else if (!to && from) {
        return date >= from;
      } else {
        return true;
      }
    }).slice(0, limit || user.exercises.length);
    
    return res.json({
      _id: user._id,
      username: user.username,
      log: log,
      count: user.exercises.length
    });
  })
});

It is working correctly as I test it a couple of times. All other tests are passing also.

try to get data from query like this
let { userId,from,to,limit} = req.query;
after that you can get all users by that id and check if “from” is undefined if its not undefined
filter array with

data = data.filter((data) => {
      let from_date = new Date(from);
      let now_date = new Date(data['date'])
      return from_date <= now_date
    })

in this case data is exercises of user
you can filter the same array for “to” don’t forget to change this line
return from_date <= now_date

Thanks, but the test about filtering is good. I have an issue with the second to last test. Here is the message I get:

I can retrieve a full exercise log of any user by getting /api/exercise/log with a parameter of userId(_id). App will return the user object with added array log and count (total exercise count). (Test timed out)
// tests completed

All other tests are passing. I also test it manually and it returns the right data. I guess there is a little timeout set in the test itself or maybe something else I don’t get from reading the instructions

I added a middleware to check all incoming requests when running the tests and everything seems fine. I even tried the urls manually and the app is responding as it should be.

You’re right it times out can you send your link to your app

garrulous-blossom-selenium .glitch .me

Here you go. I guess it happens because I use MongoDB Atlas and it has a delay when fetching data from it. My best guess is that the test is somehow configured to check for a very little timeout.

Well i can create new users without problem but when i try to add new exercise to that user it not responds.
Can you send your whole server.js file

Wow! I fixed the way I process dates and it passed. I can’t tell why the hell did it pass the test for adding exercise, but failed the one that reads. The problem was in my /api/exercise/add endpoint, which is not related to the issue I had…
Anyway thanks! However, I think the tests should be reviewed.

Congrats, i think you’re right someone opened issue on github 2 hours ago


same problem as yours

1 Like

Too bad they closed it already. I’m failing this test as well even though my app literally returns the output described in the challenge. And on the closed bug they said “Unfortunately, the tests do not align perfectly with the challenge descriptions, and are extremely specific.” But if this isn’t being accepted as an actual bug, why not at least add wording to the challenge descriptions to to be as “extremely specific” as the tests? Why acknowledge the problem with ambiguity while doing nothing to address that ambiguity?

1 Like

Hello there.

Please understand, the above issue was closed as it was unclear as to where the issue lay. This forum post being opened is exactly what I have been looking for to get a discussion going on the issue. I will reopen the issue.

As for many of the Backend challenges and projects, multiple issues are already open, and in discussion going about syncing the instructions with the tests, as well as improving the tests. We do apologise for the frustration caused.

1 Like

Thank you. I also noticed that liked my tips on another user’s Curriculum Help post, now that I’ve finally gotten through the tests, so I will share a link to that post here in case it’s helpful to others in the meantime. Exercise Tracker works but not passing