See info below. I’m not sure what I can do to make this test pass, or even if it’s totally within my control. It seems to be the result of some sort of lag. The test DID pass on one occasion, and I thought I had fixed it by moving the line that assigns the timestamp to an earlier place in the code. However, it has not passed since. Please help!
This is the test description and error at the bottom:
You can send a POST request to /api/replies/{board} with form data including text, delete_password, & thread_id. This will update the bumped_on date to the comment’s date. In the thread’s replies array, an object will be saved with at least the properties _id, text, created_on, delete_password, & reported.
// tests completed
// console output
[Error: expected ‘2023-05-29T21:54:02.719Z’ to equal ‘2023-05-29T21:54:03.175Z’]
Here’s my full code: boilerplate-project-messageboard - Replit
Here’s the code for that route:
app.route('/api/replies/:board')
.post(async (req, res) => {
let {thread_id, text, delete_password} = req.body;
let {board} = req.params;
let boardDoc = await MessageBoard.findOne({name: board});
let threadDoc = await boardDoc.threads.id(thread_id);
if(!boardDoc || !threadDoc) {return res.json({error: 'documents not found'})}
let timestamp = new Date();
threadDoc.bumped_on = timestamp; // I believe this is the timestamp in question
delete_password = bcrypt.hashSync(delete_password, 10);
let reply = new Reply({
text: text,
created_on: new Date(),
delete_password: delete_password,
reported: false
})
threadDoc.replies.push(reply);
await boardDoc.save();
return res.redirect(`/b/${board}/${thread_id}/`)
})