Create/update Comments not working

I have been doing this task for 2 days but unable to complete it. I have seen all the issues available and tried every possible solution but still, this doesn’t help.

expect(received).toEqual(expected)

Expected value to equal:
  "5c9a1ccbbece11147c5f5fc0"
Received:
  "5a9427658b0beebeb697bc39"

Difference:

- Expected
+ Received

- "5c9a1ccbbece11147c5f5fc0"
+ "5a9427658b0beebeb697bc39"

  55 |     const martianComments = (await MoviesDAO.getMovieByID(movieId)).comments
  56 |
> 57 |     expect(martianComments[0]._id).toEqual(postCommentResult.insertedId)

this is my error snippet.

I have exactly the same. CommentsDAO.addComment returns the object but it is not saved in my DB…

When adding to DB, the newest comment is listed last in movies’ comments array, and the test expects the newest comment to also be the first (martianComments[0] - date sorting of comments).

You need to work around the aggregation pipeline and sort the comments based on date, and return.

@Ravi_Pandey_69903, please follow forum guidelines and help others by helping them finding the error not by giving them the answer.

Sorry @steevej-1495, wasn’t aware of that. I’ll edit my response to ‘not give direct answer’.

1 Like