Exercise Tracker - Nothing Passes?

Hi guys,

I’m really tired after working on this for several days after work but expected most stories to pass when I submitted this but none of them do except the unique URL test. I must have done something to my code to upset the test suite. Not sure if its the file structure or something else? Or maybe I just got it all wrong :slight_smile:

Your project link(s)

solution: https://rsheppard-exercise-tracker.herokuapp.com
githubLink: GitHub - rsheppard-dev/exercise-tracker

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.101 Safari/537.36

Challenge: Exercise Tracker

Link to the challenge:

I tested a couple endpoints manually and it looks good. I wonder if the worm-up time for Heroku is throwing off the test runner? I’m not really sure how the tests work. But maybe try getting the tests to run several times in a row?

1 Like

I’ve used Heroku for my other projects in this section and its worked fine. I might copy the code over to repl.it and see if it makes a difference.

Hello there,

Remember, you can often get a lot of information in the browser devtools Console and Network tabs:

Access to fetch at 'https://rsheppard-exercise-tracker.herokuapp.com/api/users'
from origin 'https://www.freecodecamp.org' has been blocked by CORS policy:
No 'Access-Control-Allow-Origin' header is present on the requested resource.
If an opaque response serves your needs, set the request's mode to
'no-cors' to fetch the resource with CORS disabled.
frame-runner.js:98 TypeError: Failed to fetch

Hope this helps

1 Like

Thanks Sky. (Sorry, feel like this is a stupid question) Would I be checking devtools on the freecodecamp submit page after sending? Or inspect my hosted project?

I read up a bit on the error you showed me and I thought the Cors package was meant to deal with this? I moved the Cors package up so it was the first to be used by express, incase that matters and I did manage to pass one extra test, which was:

You can make a GET request to /api/users to get an array of all users. Each element in the array is an object containing a user’s username and _id .

The rest of the tests still fail although they seem to work for me. It’s hard to debug as I don’t know what the test is looking for besides the instruction it gives.

Really appreciate any help!

Your code certainly looks fine. It’s perplexing that you pass Test 3 but not Test 2. The correct data seems to be coming back okay. When I check the Network traffic on the Web Inspector, I noticed there’s an error

An error occurred trying to load the resource

Wonder if this has anything to do with the problem. The list includes css and style.css. The header info is

Summary
URL: https://rsheppard-exercise-tracker.herokuapp.com/style.css
Status: 200 OK
Source: Memory Cache
Initiator: 
rsheppard-exercise-tracker.herokuapp.com:7

Request
No request, served from the memory cache.

Response
Content-Type: text/css; charset=UTF-8
Access-Control-Allow-Origin: *
Via: 1.1 vegur
Cache-Control: public, max-age=0
Date: Wed, 16 Jun 2021 20:00:38 GMT
Content-Length: 830
Connection: keep-alive
ETag: W/"33e-17a1101c2f0"
Accept-Ranges: bytes
Last-Modified: Tue, 15 Jun 2021 18:49:26 GMT
X-Powered-By: Express
Server: Cowboy

Is the style.css file referenced correctly from index.html?

Also, is there a spec to disallow the user name less than 4? I don’t remember such constraint given. I wonder if FCC test tries to add a user like ‘Jon’.

1 Like

I removed the minlength and maxlength from the username Schema and it made user story 2 :slight_smile: Thank you!

I am still failing story 4, 5, 6 and 7 and can’t work out why.

I don’t see an issue with the css and haven’t edited it or the link in the index.html.

Thanks for the help so far. Can’t believe how much trouble it has been to get this to pass!

I’m glad to hear my suggestion worked. All other errors may be similar in nature, that is, you’re doing more than what they want you to do.

Your link in index.html is

<link href="style.css" rel="stylesheet" type="text/css">

Shouldn’t it be

<link href="./../public/style.css" rel="stylesheet" type="text/css">

Don’t know if this has to do anything with the errors at hand, though.

Here’s another thing I noticed. After adding a user and attempting to add a new exercise to this user, I entered no information (other than user id), then I got this

{"errors":{"description":{"name":"ValidatorError","message":"Path `description` is required.","properties":{"message":"Path `description` is required.","type":"required","path":"description","value":""},"kind":"required","path":"description","value":""},"duration":{"name":"ValidatorError","message":"Path `duration` is required.","properties":{"message":"Path `duration` is required.","type":"required","path":"duration","value":null},"kind":"required","path":"duration","value":null}},"_message":"Exercise validation failed","name":"ValidationError","message":"Exercise validation failed: description: Path `description` is required., duration: Path `duration` is required."}

Even though the form puts * to description and duration, the spec doesn’t really say that. So it’s possible that they don’t like this reply. In other words, just add the exercise even if those fields are blank. I don’t think I put such validation and I passed the FCC tests, so judging from what happened so far, this could be the cause.

1 Like

The style sheet should be referenced by the app.use(express.static(‘public’)) code in server.js so it knows where to look for static assets.

I will try what you suggested. I know I also put some custom validation on username to check if it exists so will check thats not messing things up.

I’ve removed the required validation from the exercise schema and another test passed which seems odd as I’m making the app worse to make it work :slight_smile:

Still three tests not working. Getting there slowly. Really appreciate all the help so far but really would like some advice on how to pass last three. This is a nightmare lol

Sorry to bump this. I have stripped out pretty much all validation that might be interfering with the tests and still no progress.

I cannot get story 5, 6 and 7 to pass. I feel like I’ve tried everything.

I looked at your code again, and there’s nothing that is obviously wrong, of course. Program is nicely organized and implemented. Unfortunately the FCC tests only check whether the code returns what they want. I tried manually and the results seemed all good. I suspect there’s one thing that is causing the last three failures. That query strings of startdate, enddate and limit somehow making the number log result different from what they’re expecting, maybe. When the dates are not there, which dates used could be different. Another possibility is that although it passes the specific test, somehow the exercise of a user is not added correctly to the database.

One last thing. Probably it won’t change anything, but when I ran your code last time and getting a list of users, I noticed another attribute _v:0 is included.

1 Like

I have finally got all tests to pass. I refactored my code and instead of using virtuals to populate the exercise log, I just used the mongoose Schema.find method to find the userId attached to each exercise to display it.

Works exactly the same but just coded it in a different way.

Thanks to everyone that helped me. That was a headache :slight_smile:

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