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.