Issue Tracker -- Stuck on last 2 tests

I have passed 9/11 tests, but I cannot get these last two tests on the issue tracker to pass. It’s not clear to me what I’m going wrong. Can anyone help?

FCC Issue Tracker requirements: https://www.freecodecamp.org/learn/quality-assurance/quality-assurance-projects/issue-tracker

My source code: GitHub - camchardukian/FCC-Project-Issue-Tracker

My deployed app: https://FCC-Project-Issue-Tracker-4.camchardukian.repl.co

Failing Test #1

The POST request to /api/issues/{projectname} will return the 
created object, and must include all of the submitted fields. Excluded
optional fields will be returned as empty strings. Additionally, include
 created_on (date/time), updated_on (date/time), open (boolean, true 
for open - default value, false for closed), and _id.

I did research and it seems this test may be failing because I have managed the created_on and updated_on values with my Mongo schema rather than updating them directly. I feel like using the Mongo schema to manage these values is less error-prone, but if this is indeed the issue I can change my code to match the needs of the project!

Otherwise, if there’s another issue or a different problem with my code I’d appreciate any help in identifying it.

Failing Test # 2

You can send a PUT request to /api/issues/{projectname} with an _id and one or more 
fields to update. On success, the updated_on field should be updated, and returned 
should be {  result: 'successfully updated', '_id': _id }.

I really can’t figure out why this test is still failing.

Conclusion

Again, any guidance or direction you can give for either of these issues would be much appreciate. Thank you so much! :smiley:

For the first issue i think you didn’t return date in response.
And for the second issue you need that: On success, the updated_on field should be updated updated_on field should be updated

1 Like

I have fixed the first issue, but the 2nd issue still persists.

Here is my function:

editIssue: (req, res) => {
    const {
      _id,
      issue_title,
      issue_text,
      created_by,
      assigned_to,
      status_text,
      open = undefined
    } = req.body;
    const params = {
      issue_title,
      issue_text,
      created_by,
      assigned_to,
      status_text,
      open
    };
    const filteredParams = Helper.removeUndefinedAndEmptyStringValuesFromObj(
      params
    );
    let projectName = req.params.project;
    if (!_id) {
      return res.json({ error: "missing _id" });
    } else if (Helper.checkIsEmptyObject(filteredParams)) {
      return res.json({ error: "no update field(s) sent", _id: _id });
    } else {
      Project.findOne({ projectName }, (err, docs) => {
        if (err || !docs) {
          return res.json({ error: "could not update", _id: _id });
        }
        const issueToBeUpdated = docs.issues.id(_id);
        if (!issueToBeUpdated) {
          return res.json({ error: "could not update", _id: _id });
        }
        issueToBeUpdated.issue_title =
          issue_title || issueToBeUpdated.issue_title;
        issueToBeUpdated.issue_text = issue_text || issueToBeUpdated.issue_text;
        issueToBeUpdated.created_by = created_by || issueToBeUpdated.created_by;
        issueToBeUpdated.assigned_to =
          assigned_to || issueToBeUpdated.assigned_to;
        issueToBeUpdated.status_text =
          status_text || issueToBeUpdated.status_text;
        issueToBeUpdated.open = open || issueToBeUpdated.open;
        docs.save((err, data) => {
          if (err || !data) {
            return res.json({ error: "could not update", _id: _id });
          } else {
            return res.json({ result: "successfully updated", _id: _id });
          }
        });
      });
    }
  },

Here is the test I believe I’m failing:

async (getUserInput) => {
  try {
    let initialData = {
      issue_title: 'Issue to be Updated',
      issue_text: 'Functional Test - Put target',
      created_by: 'fCC'
    };
    const url = getUserInput('url') + '/api/issues/fcc-project';
    const itemToUpdate = await $.post(url, initialData);
    const updateSucccess = await $.ajax({
      url: url,
      type: 'PUT',
      data: { _id: itemToUpdate._id, issue_text: 'New Issue Text' }
    });
    assert.isObject(updateSucccess);
    assert.deepEqual(updateSucccess, {
      result: 'successfully updated',
      _id: itemToUpdate._id
    });
    const getUpdatedId = await $.get(url + '?_id=' + itemToUpdate._id);
    assert.isArray(getUpdatedId);
    assert.isObject(getUpdatedId[0]);
    assert.isAbove(
      Date.parse(getUpdatedId[0].updated_on),
      Date.parse(getUpdatedId[0].created_on)
    );
  } catch (err) {
    throw new Error(err.responseText || err.message);
  }
};

And here is the error I’m still getting:

frame-runner.js:98 Error: expected undefined to be an object
at eval (eval at <anonymous> (frame-runner.js:84), <anonymous>:28:11)

And ideas? I thought maybe the created_on or updated_on fields weren’t defined, but even after trying to fix them I’m still getting the same error. :worried:

Do you sure you update the updated_on if success?

Yes, I tried updating the updated_on yesterday with this code but it also failed so I didn’t bother pushing it to GitHub (I apologize for not including this in my post a couple hours ago).

  editIssue: (req, res) => {
    const {
      _id,
      issue_title,
      issue_text,
      created_by,
      assigned_to,
      status_text,
      open = undefined
    } = req.body;
    const params = {
      issue_title,
      issue_text,
      created_by,
      assigned_to,
      status_text,
      open
    };
    const filteredParams = Helper.removeUndefinedAndEmptyStringValuesFromObj(
      params
    );
    let projectName = req.params.project;
    if (!_id) {
      return res.json({ error: "missing _id" });
    } else if (Helper.checkIsEmptyObject(filteredParams)) {
      return res.json({ error: "no update field(s) sent", _id: _id });
    } else {
      Project.findOne({ projectName }, async (err, docs) => {
        if (err || !docs) {
          return res.json({ error: "could not update", _id: _id });
        }
        const issueToBeUpdated = docs.issues.id(_id);
        if (!issueToBeUpdated) {
          return res.json({ error: "could not update", _id: _id });
        }
        const currentTime = await new Date();
                issueToBeUpdated.created_on = issueToBeUpdated.created_on;
                                issueToBeUpdated.updated_on = currentTime
        issueToBeUpdated.issue_title =
          issue_title || issueToBeUpdated.issue_title;
        issueToBeUpdated.issue_text = issue_text || issueToBeUpdated.issue_text;
        issueToBeUpdated.created_by = created_by || issueToBeUpdated.created_by;
        issueToBeUpdated.assigned_to =
          assigned_to || issueToBeUpdated.assigned_to;
        issueToBeUpdated.status_text =
          status_text || issueToBeUpdated.status_text;
        issueToBeUpdated.open = open || issueToBeUpdated.open;
        docs.save((err, data) => {
          if (err || !data) {
            return res.json({ error: "could not update", _id: _id });
          } else {
            return res.json({ result: "successfully updated", _id: _id });
          }
        });
      });
    }
  },

No problem, if you look at the error message

run your code and find out the code that response with undefined

There’s either no error locally or seemingly no way for me to view it. That’s why I’m posting here. I can only see the error in the console on FCC which is why I believe the error comes from the test I cited above.

Before the last docs.save put console.log(issueToBeUpdated) and tell me if the output is correct for you. you use

and issueToBeUpdated you want it’s value to change so you should use let instead of const

I found the problem when you get specific issue with it’s id it return an empty array [] and the response should be [{issue object}]

After a lot of tweaking I finally fixed it. Thanks a lot for your help :smiley:

1 Like

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