Error in Usermangment Ticket

in addUser function If I use
await users.insertOne(userInfo) instead of await users.insertOne({ …userInfo })

The Test is Fail I can’t figure out why is this happens?

It’s understandable to have a hard time finding those weird dots, here you go https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax

I know the spread operator but I don’t know why it’s no passing the test here.
I’m frustrated

OK, here is what happens…
When you pass your variable to the insertOne function your variable is mutated, _id is appended to your user info. Then after deleting the _id in the tests the program expect the id to be missing in both result and function argument. I hope that the screenshots below will help you understand what is happening (and help you sleep better :slight_smile: tonight and avoid being frustrated), this is a side effect of using the insertOne with passing a variable (google it).


P.S. Personally I prefer the below approach (this is why I did not payed attention to the side effect you are facing).
let { name, email, password } = userInfo and then add each in the insertOne method, it kind speaks for itself and describes what I am exactly trying to do/ add in DB.

1 Like