Issue tracker certification project

Tell us what’s happening:
Hi, I’m currently working on the issue tracker in the quality assurance certification.

I was able to make the POST function (aka creating an issue), and moved onto the PUT and DELETE api.

currently, the following test passes: ’
When the PUT request sent to /api/issues/{projectname} does not include an _id, the return value is { error: 'missing _id' }

but none of the other PUT requests nor the delete request pass. When I try out updating an issue on the webview, it works for me with all the cases of:
-when there is an id, but no update fields, I’m getting the following: {"error":"no update field(s) sent","_id":"[with whatever id I entered]"}

-when there is an id, update fields, but the id is not valid, I’m getting: {"error":"could not update","_id":"[with whatever invalid id I entered]"}

-when there is a valid id and update fields, I’m getting: {"result":"successfully updated","_id":"654949a1999bbc8c7519e207"} and checking with my mongoDB it updated it correctly.
I’m not sure whats wrong with my code for it to not pass for that specific test.

I’ve tried the same with the delete, and on my webview, it’s working.

I’ve checked with the github, to take a look at the exact tests it is doing: https://github.com/freeCodeCamp/freeCodeCamp/blob/main/curriculum/challenges/english/06-quality-assurance/quality-assurance-projects/issue-tracker.md

and couldnt find why it wouldnt pass.
I also checked with the sample website: https://issue-tracker.freecodecamp.rocks/
and I found that it works differently. It doesn’t give an error message when updating an issue without any update fields, it actually gives the result of successfully updated.

and on the delete issue, it doesnt give an error message if it’s an invalid id, it doesnt give any result.

I’m a bit stumped on what is causing the issue for my tests not to pass, would anybody mind taking a look?

Your code so far

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/117.0

Challenge:
issue tracker

Link to the challenge:

I didn’t look but I assume you have to implement the GET part so the tests can check the PUT. The return from the PUT is likely not enough to actually check if the PUT was successful, so it does a GET after the PUT to check it and you have no code for that.

1 Like

I’ve added the get function to get the full array of it (without the filter function yet) and I get the same result with [url]/api/issues/apitest/ for my website and the test website, with all fields present.

But that one also doesn’t pass the test, and the PUT and DELETE also don’t pass…

I also find it confusing that the sample site passes on the tests, but when I try on it, i.e. a valid ID but no updating fields, which should give the error with ‘no updating field(s)’, it instead gives ‘successfully updated.’

any insight is appreciated

Use the browser dev tools and look in the network tab to inspect the request/response when you submit. The browser console will also log assert errors.


Change to res.json in the GET and make sure you have a return after all your res calls to avoid any “header was already set” errors.

After the first PUT it then does a GET using a query string but you do not have any logic set up for that GET.

Doing the GET last seems very backward and I wouldn’t suggest doing that. There is a high chance that the tests need the GETs to be implemented to test whether the POST/PUT/DELETE routes are doing what is expected.


There are two things that may happen when an “update” method (PUT/POST/PATCH/DELETE) is tested.

  1. After the update, the route handler might return “something” that the test can check (like a string saying “success”).

  2. Then the test may fetch against the GET and check the response to see if the update was actually successful (i.e. the DB was updated correctly by looking at the response that was sent back).

The two are not directly connected but a test may combine them.

2 Likes

You should provide the req.params
And req.body

Both to pass the test, I tackled the same issue before taking the certificate

You might need to provide the id as “:_id”

2 Likes

It’s essential to ensure your code aligns with the challenge requirements. Debug, review tests, and compare with the sample website to find discrepancies.

1 Like

This together with looking at req.params and the req body solved most issues, thank you so much.
Especially that note about having a return after all res calls, similar to do GET requests before actually looking if api calls pass is fantastic to know, thank you.

I’m now passing every test except for the functional tests(which still need to be done) and this:
‘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 }

I’m wondering if I might be misunderstanding that requirement.
The way that I interpret that one at first together with the one right above it ( When the PUT request sent to /api/issues/{projectname} does not include an _id, the return value is { error: 'missing _id' })is:
if there is an _id is input but nothing else, like in this picture:

it should produce the message { error: 'no update field(s) sent', '_id': _id }

and then any other error, which as far as I understand could only be if there is an id input that is not valid together with any update field like this:
image
and on this, it should answer with : { error: 'could not update', '_id': _id }
Having it like that didn’t pass the test.

On the sample site, it works differently. Having just a valid id will provide the message:
{"result":"successfully updated","_id":"654ab0d750199d001361306f"}
and when you have an invalid id, it’ll provide the { error: 'could not update', '_id': _id }
Which would mean the error with no update field(s) sent would only be sent if there is no input (neither id nor any other) but that’s something I can’t test since the id is required by the form.
However, if I change my code to work like that, it still doesn’t pass the test. Am I missing something about this requirement?

any ideas why it might not pass? I managed to run all 14 tests, the only thing now not passing is that requirement, and I can’t figure out where it is wrong, as when I input the example, it gives out what it is asking for.
Checking with the actual test on github, and putting that test in also gives the expected result, and yet it isn’t passing.

Hey @tim-la,

It looks like your logic is slightly off in the PUT side of things. I would first test to see if there is no req.body._id before trying to find the id in your issue finder. Return the specific error message if there is no _id in req.body._id and then if that passes, initialize the let id portion.

Next, check to see if the update fields are missing, and then return that specific error message if they are all missing.

And if those two conditions pass continue on with your update process. Any generic error that gets produced will run through the try/catch and have that generic error message in its returned value.

You don’t need any else if conditions since you are issuing a return in the if statement, as well. In JavaScript, a return will exit that function as soon as it is called, which makes testing for an else if redundant.

1 Like

Also, log out the values in your else if in the PUT and make sure the values (the req.body values) are what you expect them to be (when you submit the challenge).

1 Like

Thank you,

I’m really trying, but I don’t see where it is off. I changed the else if (thank you for that knowledge with the return it exits the function) as well as where I initialize the let id portion.

I’m logging on every output, and the result of my logs, as far as I can tell, is what is needed.

On my output for missing update fields, if I log the req.body, I get the object of _id with the id I input, together with issue_title, issue_text, created_by, assigned_to and status_text as ''.

and on my output for could not update, it is the object of _id with whatever I input to update as well as the other values as ''.

I tried taking out the portion for when the _id is not a valid _id, and have the catch report that error message, but it also doesn’t pass the test. I’m at a loss.

Did you log out the values in the PUT handler and submit so the tests run?

console.log(req.body.issue_title, req.body.issue_text, req.body.created_by, req.body.assigned_to, req.body.status_text)

Hint: The values are not what you think they are.

1 Like

I appreciate the help.

I’m sorry, I don’t understand. I log out the values. When I input an invalid or valid ID together with the new issue_title of 'new title'
the log of issue_title is 'new title' while all others are ''
I don’t get it.

Like I said, submit the project and let the tests run.

To save you some time, I can tell you they are not empty strings.


As an aside, you rarely want to check for literal values when doing falsy/truthy checks. It is often better to let the language do the coercion.

2 Likes

okay. they’re running as undefined, which meant that if I changed my requirement from them being '' to undefined, it passes.

Why is it different running the tests via the website versus testing the website in the webview? when I tested it in the website itself, instead of undefined, it gave me ''.
Do you know by any chance?

Also, now, when I’m on the website and I only have an ID filled in, it doesnt give that error message of no update field(s) sent as a result, instead gives the successfully updated.
Is that one of those moments of just, accept how it is and move on? :slight_smile:

(also, I really appreciate your help and all.)

Using an API “headless” is not the same as using it with a website. When you use the form and the inputs are empty they return an empty string. When JS code (e.g. fetch) bypasses the user interface and hits an endpoint directly the missing values are not empty strings, they are missing values, which for the most part are always undefined.

It is for the same reason you can not rely just on client-side validation as a user may “bypass” your user interface and hit your endpoints directly. Doing who knows what you didn’t account for.

2 Likes

that makes a lot of sense. Thank you, this is all fantastic information to know.
Onto the next challenge, and I hope you have a great rest of your day/night

1 Like