Ticket: User Management - Two tests failed

Here is the result :
User Management
× it can add a new user to the database (298ms)
√ it returns an error when trying to register duplicate user (266ms)
× it allows a user to login (529ms)
√ it allows a user to logout (530ms)
● User Management › it can add a new user to the database
Received: undefined
29 | */
30 | const actual = await UsersDAO.addUser(testUser)
> 31 | expect(actual.success).toBeTruthy()
| ^
32 | expect(actual.error).toBeUndefined()
33 |
34 | // we should be able to get the user

How to solve this issue?

Should I dive into user-management.test.js file?

Yes, looking at the test file will give you an idea on what the test are expecting from your code.


My advice for other users who get a similar error.

Take a closer look at user_id.

For example => Inside the method deleteUser (already given to you).

  static async deleteUser(email) {
    try {
      await users.deleteOne({ email })
      await sessions.deleteOne({ user_id: email })
/* rest of the code */

You find a very big hint on the comment inside loginUser function:

// matching the "user_id" field with the email passed to this function.

“matching” == “matching the query” -

For example Match the name field with the value Bob (In the Q we use function parameter instead of plain text):

{ name: "bob" }

1 Like