Ticket: User Management M220JS

I’m completing the add user function in the following way

try {
// TODO Ticket: User Management
// Insert a user with the “name”, “email”, and “password” fields.
// TODO Ticket: Durable Writes
// Use a more durable Write Concern for this operation.
await users.insertOne({
name: userInfo.name,
email: userInfo.email,
password: userInfo.password,
})
return { success: true }
} catch (e) {
if (String(e).startsWith(“MongoError: E11000 duplicate key error”)) {
return { error: “A user with the given email already exists.” }
}
console.error(Error occurred while adding new user, ${e}.)
return { error: e }
}
}

but I obtain the following error

● User Management › it can add a new user to the database

expect(received).toEqual(expected)

Expected value to equal:
  {"email": "magicz@cats.com", "name": "Magical Mr. Mistoffelees", "password": "somehashedpw"}
Received:
  {"email": "email", "name": "name", "password": "password"}

Difference:

- Expected
+ Received

  Object {
-   "email": "magicz@cats.com",
-   "name": "Magical Mr. Mistoffelees",
-   "password": "somehashedpw",
+   "email": "email",
+   "name": "name",
+   "password": "password",

Any help please. Thanks

Did you mess with the testUser object in the user-management.test.js?

It should be:

const testUser = {
  name: "Magical Mr. Mistoffelees",
  email: "magicz@cats.com",
  password: "somehashedpw",
}

I think I did. I cannot undersatnd why I’m having that result, but I cannot obtain the ticket neither

@Raul_24928 How is this going, is it resolved?

If not, would you insert the line console.log("User info ===>", userInfo) just above the await users.insertOne call in your code, like so:

try {
// TODO Ticket: User Management
// Insert a user with the “name”, “email”, and “password” fields.
// TODO Ticket: Durable Writes
// Use a more durable Write Concern for this operation.
console.log("User info ===>", userInfo)
await users.insertOne({
    name: userInfo.name,
    email: userInfo.email,
    password: userInfo.password,
})

Then look for that line in your test output? Let us know what it says.