Exercise Tracker: Two versions, each getting different test input

I rewrote my Exercise Tracker, which was able to pass all the tests, so that the server logic and database logic were in separate files, but, even though the code is largely the same, it’s now unable to pass Tests 10 through 15, all of which involve GET /api/users/:_id/logs. (Interestingly, it can pass Test 16.)

What’s also bizarre is that, while my original version never appeared to get requests for exercise logs for users that didn’t have any exercises added yet, the newest one does—a lot, in fact. I updated my code so that it will return a user object where count = 0 and log = [] for those cases, but it still can’t pass all the tests.

Here’s an example of some output from my new version:

User created:
{ username: 'fcc_test_16512089598', _id: '626b72ffe4fe116f680d28d0' }

Exercise log requested:
  _id: '626b72ffe4fe116f680d28d0',
  username: 'fcc_test_16512089598',
  count: 0,
  log: []

(Note: The empty object underneath the Exercise log requested text represents the contents of req.query.)

As you can see, the test requested the exercise log for a user immediately after creating it. And it actually did it again to the same user later in the test even though it still hadn’t added anything to that user. Nothing at all like this happens when using my original program. I’ll put links to them below, so please feel free to try running them. You will see just how different the input they get from the test routine is.

Replit for original version

Replit for updated version

I would like to know if anyone else has experienced something like this. I’m just so confused about why the updated version can’t pass all the tests even though the code is mostly the same (save for the fact that it’s separated into two files now). If it’s possible to have someone look at it, I can post links to each version on my GitHub. Thank you in advance.

I took a quick glance and stopped. I created username Dad user id 626b8da2c08db0478b0be7f4 . Your app let me post an exercise without a description or duration which are required fields. I stopped after that. using updated version.

original Mr Bean

_id	"626b8e9254f3ed474ca0c221"
username	"Mr Bean"
description	""
duration	0
date	"Thu Apr 28 2022"
description	"Beer"
duration	10
date	"Thu Apr 28 2022"
count	2

looks ok ecxept a log with no description or duration again. I would try and fix that first.

Also search the forum regarding time zone issues with this project. My project would pass only when my timezone matched whatever , I never investigated. I submitted just after midnight Eastern time and passed.

Thank you for taking the time to look at my project. I made sure to implement those changes, so it should be much more robust now and unforgiving of invalid input. Hopefully. Unfortunately, however, it still fails Tests 10 through 15. My original version did have trouble with Test 15 due to the time zone issue, but that was the only issue. I’m still confused about why this one is having so many problems.

1 Like

No, the test values aren’t changing (except for the time related bits). You need to log all inputs and outputs for your POST exercise and GET log routes and you’ll get something like

User created:
{ username: 'fcc_test_16512719146', _id: '626c68eaded2063e9a549cdd' }
# I should be creating and exercise, but I'm not...
post exercise
req.body: {"description":"test","duration":"60"}
req.params: {"_id":"626c68eaded2063e9a549cdd"}
req.query: {}
# No exercise, no log, tests fail.
req.body: {}
req.params: {"_id":"626c68eaded2063e9a549cdd"}
req.query: {}
  _id: '626c68eaded2063e9a549cdd',
  username: 'fcc_test_16512719146',
  count: 0,
  log: []

with this from the last failing test (all are basically the same). The spec allows for missing dates (which default to now) which is where this particular test is currently failiing. So the code is getting the same input data but this new version is not always saving the records.

More importantly, you have some .then() calls to get your data, but no .catch() calls to check for errors. The results of that may be helpful.

When you’re chasing errors like this you really have to log all your possible errors and log your inputs and every possible output to see what is happening and where. When you separate functions from your routes, you also need to log from those separate functions too.


That was it: I wasn’t allowing for null dates in the new code. I fixed it, and it passes all the tests now. Thank you so much!

1 Like

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