Issue Tracker, only post requests pass

Tell us what’s happening:
I’m trying to finish my issue tracker app, but I’ve run into an issue where the only tests that pass are the post requests. I know that they are all not done yet, but I can’t tell whats wrong with my delete requests or my get requests, as the get request should be passing with no parameters easily.

Your code so far
My repl all routes are in the api.js file.

Your browser information:

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

Challenge: Issue Tracker

Link to the challenge:

Hello there,

Top Tip: Use your devtools, when you submit, to get more information about the failed tests:


Couple that with the tests: freeCodeCamp/issue-tracker.md at master · freeCodeCamp/freeCodeCamp (github.com)

Now, you can quite a bit more easily debug.

Hope this helps

1 Like

Thanks so much! being able to find the tests is a HUGE help!

Ok, I’ve gotten a bit more of a handle on things now, that was very helpful!. I’m certainly not done, and realized that I should probably have the mocha tests written, as they’ll help me debug even easier.

I wrote the first one, but it does not work at all. I’m getting the following error:

Tests are not valid:
/home/runner/boilerplate-project-issuetracker/tests/2_functional-tests.js:11
    test('create with every field', function(done){
    ^^^^

SyntaxError: Invalid destructuring assignment target
    at wrapSafe (internal/modules/cjs/loader.js:1053:16)
    at Module._compile (internal/modules/cjs/loader.js:1101:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
    at Module.load (internal/modules/cjs/loader.js:985:32)
    at Function.Module._load (internal/modules/cjs/loader.js:878:14)
    at Module.require (internal/modules/cjs/loader.js:1025:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at /home/runner/boilerplate-project-issuetracker/node_modules/mocha/lib/mocha.js:394:36
    at Array.forEach (<anonymous>)
    at Mocha.loadFiles (/home/runner/boilerplate-project-issuetracker/node_modules/mocha/lib/mocha.js:391:14)
    at Mocha.run (/home/runner/boilerplate-project-issuetracker/node_modules/mocha/lib/mocha.js:970:10)
    at EventEmitter.emitter.run (/home/runner/boilerplate-project-issuetracker/test-runner.js:58:32)
    at Timeout._onTimeout (/home/runner/boilerplate-project-issuetracker/server.js:56:16)
    at listOnTimeout (internal/timers.js:549:17)
    at processTimers (internal/timers.js:492:7)

It is just a small syntax error on this line:

 suite('POST tests',function({

Hope this helps

1 Like

Hi again, If you could possibly help me out again, I’m getting this error in the dev console when I run the free code camp tests on the app .

Error: expected { Object (result, _id) } to deeply equal { Object (error, _id) }
    at eval (eval at <anonymous> (VM66 frame-runner.48f6f4fc3b0f26107e07.js:32), <anonymous>:23:11)

but I’m outputting everything and it is returning the right format object when its supposed to. I really can’t seem to figure out whats going wrong. This appears to be an issue with my put requests.

once again, my repl

On a quick glance, I would say just to be sure you are breaking out of any execution, once you respond. That is, use return res.json(...); where applicable.

Let me know if that helps

Ok so everything works properly for the user, like you can do all the CRUD operations, and I’ve written the tests out, which work properly. I’m still getting the error I mentioned above, as if they’re looking for the wrong output when I run the tests.

I have narrowed it down to this test:

const badIdUpdate = await $.ajax({
      url: url,
      type: 'PUT',
      data: { _id: '5f665eb46e296f6b9b6a504d', issue_text: 'New Issue Text' }
    });
    assert.deepEqual(badIdUpdate, {
      error: 'could not update',
      _id: '5f665eb46e296f6b9b6a504d'
    });

Here is my testing, and your app’s response:

fetch(url, {method: 'PUT', headers, body: JSON.stringify(body)}).then((data)=> {console.log(data); return data.json()}).then(res => console.log(res)).catch(e=>console.error(e))
Promise {<pending>}
VM2800:1 
Response {type: "basic", url: "https://boilerplate-project-issuetracker.sethalan.repl.co/api/issues/fcc-project", redirected: false, status: 200, ok: true, …}
{result: "successfully updated", _id: "5f665eb46e296f6b9b6a504d"}

As you can see the app response should not be as it is for the given input. (note, I gave the same input as the tests)

Hope this helps

I’m a little confused as to which block of code is which. The last one is whats expected, the third one is the response from my app? What is the second block?

Also thank you a ton for your patience and help with this project. Its extremely useful!

Sorry about that. I was rushed. The important parts:

  • What the tests are sending in a PUT request:
{
  url: url, // This is your apps url with `/api/issues/fcc-project` appended
  type: 'PUT',
  data: { _id: '5f665eb46e296f6b9b6a504d', issue_text: 'New Issue Text' }
}
  • What the tests expect as an output:
{
   error: 'could not update',
   _id: '5f665eb46e296f6b9b6a504d'
}
  • What your app outputs:
{result: "successfully updated", _id: "5f665eb46e296f6b9b6a504d"}

The stuff in-between was just extra logs I used to debug (in the end, they did not seem necessary)


A quick thought of mine is that your app is creating the project, if one does not exist.

I am glad this is helpful. We are both learning during this :smiley:

So this is the Id its sending, and it wants it to be treated as an invalid id, the problem is that it appears to be valid!? The only other issue I can think of is that its sending an id for something that it cannot update, but I think that would return an error from mongoose, as it couldn’t find a document.

and in writing this i found the solution. Mongoose returns null, not an error, if the document wasn’t found. so now my findbyidandupdate looks like this

project.findByIdAndUpdate(ObjectId(req.body._id), query,function(err, data){
            if(err){ 
              console.log('could not update error', err)
              return res.json({ error: 'could not update', '_id': req.body._id })
            }else if (data=== null){
              console.log('could not update error', err)
              return res.json({ error: 'could not update', '_id': req.body._id })
            }else{
              console.log({  result: 'successfully updated', '_id': req.body._id })
              return res.json({  result: 'successfully updated', '_id': req.body._id })
            }
          })

and the test passes, becuase it treats null as an error.
About to fix delete to do the same.

The issue wasn’t that the id was invalid, but rather that the id did not have a document associated with it.

Try this for me:

  • Clear your database completely
  • Re-run the tests

Let me know, if anything changes

EDIT: I did not read your whole thread. Congrats on getting it working :+1:

1 Like