Issue Tracker 3rd Test Not Passing

I’m working on the Issue Tracker project of the Quality Assurance section locally using vscode, The test:

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

is not passing while all other tests are passing. When I check the console,

it shows:

expected { assigned_to: ‘Chai and Mocha’, …(7) } to have property ‘status_text’

In my post route, I am returning “status_text” in the res.json so I don’t know why I’m getting that error. Below is my code

.post(async (req, res) => {
     let projectName = req.params.project;
     let issueResult;
     let { issue_title, issue_text, created_by, assigned_to, status_text } =
       req.body;
     if (!issue_title || !issue_text || !created_by) {
       res.json({ error: "required field(s) missing" });
     }
     try {
       let projectModel = await ProjectModel.findOne({ name: projectName });
       if (!projectModel) {
         projectModel = new ProjectModel({ name: projectName });
         let projectResult = await projectModel.save();
       }
       const issueModel = new IssueModel({
         project_id: projectModel._id,
         issue_title: issue_title || "",
         issue_text: issue_text || "",
         created_by: created_by || "",
         assigned_to: assigned_to || "",
         status_text: status_text || "",
         created_on: new Date(),
         updated_on: new Date(),
         open: true,
       });
       issueResult = await issueModel.save();
     } catch (error) {
       console.error(error);
     }
     // fetch the recently saved issue and get the values of the fields
     let _id = issueResult._id.toString();
     let {
       issue_title: issueTitle,
       issue_text: issueText,
       created_by: createdBy,
       assigned_to: assignedTo,
       status_text: statusText,
       created_on,
       updated_on,
       open,
     } = issueResult;

     res.json({
       assigned_to,
       status_text,  // I am returning the status text here
       open,
       _id,
       issue_title,
       issue_text,
       created_by,
       created_on,
       updated_on,
     });
   })

My source code: issue-tracker
Link to the challenge: https://www.freecodecamp.org/learn/quality-assurance/quality-assurance-projects/issue-tracker
Any help will be much appreciated.

Your repo code is missing the connection file and models folder. Please update your repo and provide a working example.


This doesn’t seem right.

let {
  issue_title: issueTitle,
  issue_text: issueText,
  created_by: createdBy,
  assigned_to: assignedTo,
  status_text: statusText,
  created_on,
  updated_on,
  open,
} = issueResult;

res.json({
  assigned_to,
  status_text,
  open,
  _id,
  issue_title,
  issue_text,
  created_by,
  created_on,
  updated_on,
});

You are destructuring the properties and renaming them, then using the old values you got from the body destructuring for the res. Unless, I’m reading that wrong.

It would help to have some working code I could run.

I do not have a live website for the code (if that’s what you mean by a working example). Your suggestion worked I was returning the old values I got from the body destructuring for the res, I fixed that and it worked thanks!

Good to hear it worked.


By working code, I just meant working code in your repo. If it is missing files and folders, it can’t really be tested.

Anyway, happy coding.