Your POST exercise route is 404’ing everything. Open the browser console while running the tests to monitor progress.
Add some logging in that route
router.post('/users/:_id/exercises', async (req, res) => {
try{
//in the html file as a property of name tien [:_id], "I don't want to change the html, it may be for internal FCC balidations
console.log(`req.body: ${JSON.stringify(req.body)}`);
console.log(`req.params: ${JSON.stringify(req.params)}`);
console.log(`req.query: ${JSON.stringify(req.query)}`);
console.log('howdy from exercises');
const _id = req.body[':_id']
const { description, duration } = req.body;
let date = req.body['date']
// if lenght too?
if(ObjectId.isValid(_id)) console.log(`isValidObjectId -> ${ObjectId.isValid(_id)}`)
if(!await User.findOne({ _id })) {
console.log(`I think user ${_id} is not in the DB.`);
return res.status(404).json({ user: 'not exist' });
}
and look at the logging output:
req.body: {"description":"test","duration":"60","date":"1990-01-01"}
req.params: {"_id":"640fa3d79698d4cd9230799b"}
req.query: {}
howdy from exercises
I think user undefined is not in the DB.
Always log the route inputs and all route responses when debugging.