[User Management]: Incorrect Test Case cause my code to fail

I ended up getting the same issue with addUser and did some testing and came to this conclusion:

If you in usersDAO.js use the code await users.insertOne(userInfo) instead of await users.insertOne({email: userInfo.email, name: userInfo.name, password: userInfo.password}) the addUser test will fail upon comparing user with testUser.

Console logging the user and testUser variables from within the test showed me that running await UsersDAO.addUser(testUser) would alter the testUser object, adding the _id property if you defined insertOne to use the full object as it’s parameter. Why this happens I believe boils down to how JavaScript handles Objects.

Regardless, this issue is fixed if you define a new object and fill in the properties separately like the second example above, alternatively like explained in the detailed answer you can also use this solution (which I personally prefer): await users.insertOne({...userInfo})

For you who’s having issues with the login part and nothing else: I assume something else is off with your code as my issue was simply on the creation part. :slight_smile:

3 Likes

I failed the login test initially and found the problem. Check that you’re inserting {name, email, password} but use {user_id: email} when dealing with sessions.