Issue Tracker project - Quality Assurance course

I have trouble with the test No. 7 of this challenge. Althought I see there nothing wrong with my solution and the data updated (I use console.log to see data). Here the freeCodeCamp challenge link:

Please help me check what is wrong with my code (in routes/api.js). Many thanks
P/S: please ignore the ‘14 functional tests’ because I didn’t write yet

So when I log your updated project (from the end of the PUT route), it produces

updated
{
  _id: 616a16df9758c6420eb153c0,
  projectname: 'fcc-project',
  __v: 1,
  issues: [
    {
      _id: 616a16df199575020b178a37,
      issue_title: 'Faux Issue Title',
      issue_text: 'Functional Test - Required Fields Only',
      created_on: 2021-10-16T00:03:43.050Z,
      updated_on: 2021-10-16T00:03:43.050Z,
      created_by: 'fCC',
      assigned_to: '',
      open: true,
      status_text: ''
    },
    {
      _id: 616a16df199575020b178a39,
      issue_title: 'Faux Issue Title 2',
      issue_text: 'Functional Test - Every field filled in',
      created_on: 2021-10-16T00:03:43.654Z,
      updated_on: 2021-10-16T00:03:43.654Z,
      created_by: 'fCC',
      assigned_to: 'Chai and Mocha',
      open: true,
      status_text: ''
    },
    {
      _id: 616a16e1199575020b178a4c,
      issue_title: 'Issue to be Updated',
      issue_text: 'New Issue Text',
      created_on: 2021-10-16T00:03:45.751Z,
      updated_on: 2021-10-16T00:03:45.986Z,
      created_by: 'fCC',
      assigned_to: '',
      open: true,
      status_text: ''
    }
  ]
}

The last one is the updated issue (note the time difference). The test does its thing, and then reports an error in the browser console of Error: expected 1634342623050 to be above 1634342623050. Those are times in milliseconds since the epoch and are the times for the first issue (no magic; the ‘050’ matches). So for whatever reason, the test is finding the first issue when it checks for updates and not the updated one.

I would check that the GET issue stuff is working as it should be, double check that no issues are getting reordered or new ids assigned, and then maybe try putting the updated issue first with unshift() instead of last with push(). Sometimes you also need to start with a clean DB (I did to no avail).

It may also be worthwhile to read the test source in fCC’s repo. These kinds of tests are difficult to debug since they use your project’s POST and GET routes to check the PUT and DELETE routes, so they all have to be working flawlessly to pass. You may also discover the problem by writing your functional tests for the last test.

1 Like

Thank you very much. The “unshift” works good instead of “push”.
And I read the test source in fCC’s repo as your recommend. So I fingure out another way to fix this problem: add a filter for “_id” in GET route because the test GET the updated issue by its “_id”