Hello there,
This is what I did to debug:
Project.findOne({ project_name: project }, (error, doc) => {
if (error) res.send(`Error: ${error}`);
if (!doc) res.send(`${project} does not exist.`);
let filteredTracker = doc.project_issue_tracker.filter(issue => {
for (const field in filter) {
if (issue[field] !== filter[field]) return false;
}
return true;
});
console.log('filteredTracker: ', filteredTracker);
res.json(filteredTracker);
});
Here are the results from the failing test:
Error: expected undefined to be an object at eval
Here is the test code:
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);
}
Specifically, look at the GET
request, and how you are finding/saving projects by _id
.
Hope this helps