I have been trying to work of the filters for the get call in the issue tracker but if I console log the req.query I just get an empty object shouldn’t the value from the url. If i put the following in the url /api/issues/{project}?open=false
shouldn’t open: false be in the req.query?
Also I have coded everything except the filters and everything seems to be working correctly but it fails most of the tests. I have examined and examined my results with the freecodecamp project and I can’t see any differences so its hard to fix because I don’t know what is wrong.
I still can’t get anything but an empty object from req.query. But I got most of the tests to pass by deleting my database and starting a new one I guess having the database populated throws off some of the tests.
When the PUT request sent to /api/issues/{projectname} does not include update fields, the return value is { error: 'no update field(s) sent', '_id': _id } . On any other error, the return value is { error: 'could not update', '_id': _id } .
it returns the proper error when no update fields are sent
it returns an error could not update for an improperly formatted id
and it returns a could not update error for a properly formatted id that isnt in the database
I also included could not update errors in all of my catches
I realize you are trying to debug the code but you really need to clean up that PUT handler code. There are not that many code paths that need to be checked.
I didn’t test it but I’m fairly sure you need to handle the “no update field(s) sent” before “could not update”. Otherwise, I think the test will just throw when it doesn’t get the expected response and never send the next PUT request (which I’m guessing is why it is missing if you look at the network requests).
So PUT > error for “no id” > PUT > error for “no update field(s)” > PUT catch all “could not update”
I just put those catches everywhere because it wouldnt pass the tests so I figured it might work. I’ll try to change the order but I think I have tried that already may not have tho.
(Yeah I switched them still getting the error its driving me nuts I even looked at the freecodcamp testing code on github. Yesterday I spent a few hours debugging my code only to find out a populated database was throwing the tests off)
I think I am just going to move on to the writing the chai tests for now maybe it will help me figure it out.
You need to check your assumptions about req.body in that PUT request. Get rid of all the other logs and label the log in the PUT request so you know what you are looking at.
Edit: BTW, Mongoose has an isValidObjectId() method.
I took a look at it and the only issue that i could see was that when there were not any update fields sent; the open issue was not in the object so I took it out of my if statement but it still doesn’t pass. I had to move the (no fields error) back above the (could not update code because it was giving incorrect results) for a valid id after i added the isValidObjectId().
Otherwise it looks fine to me I can’t really see what I am missing it seems to work correctly.
You can’t be looking at the logs correctly. The only thing that is on the body for the “no update field(s) sent” test is the id. So what is the value of a non-existing property on an object?
When I fix the conditional logic I pass all the tests except the last one for the tests you haven’t written yet.
I have put a console.log just below the put statement and in the error return and all of the fields are still returned the empty ones just show a value of “”.
.put(async (req, res) => {
try {
let project = req.params.project;
console.log('at put')
console.log(req.body)
if (!req.body._id) {
So I’m confused to where you are placing the console when it gives you non-existing properties. Do you mean check the console when the tests are run? I see what you are saying when the test is run the only thing being send is the _id and the rest of the properties are nonexisting.
Got the tests to pass by putting the above if statement as the first error check. I never tested i like that because if its in that order and an invalid Id is passed it gives the error (no update fields sent) instead of did not update error. So it passes when it is working incorrectly. I dont think that most people are checking for invalid Ids so the tests do not account for that.
What should have taken me a few minutes has taking me hours.