Step 7: Test UserDao

Let's update the corresponding tests in UserDao.test.js to account for changes we made to UserDao.js in the previous step.

Everywhere that we create a user, we must provide a password! Example:

const name = faker.name.fullName();
const email = faker.internet.email();
const password = faker.internet.password(6);
const _user = await userDao.create({ name, email, password });

Everywhere we expect the password, we should verify it! Example:

expect(verifyPassword(password, _user.password)).toBe(true);

Everywhere we can provide the password, we must check that it throws error for invalid ones. Example:

it("short password", async () => {
  try {
    const name = faker.name.fullName();
    const email = faker.internet.email();
    const password = faker.internet.password(5);;
    await userDao.create({ name, email, password });
  } catch (err) {
    expect(err.status).toBe(400);
  }
});

Refer to the commit history to see the changes made at this step.