Step 16: 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 role or let it fall back to the deafult tole! Example:

const name = faker.name.fullName();
const email = faker.internet.email();
const password = faker.internet.password(6);
const role = Math.random() > 0.5 ? UserRole.Student : UserRole.Instructor;
const user = await User.create({ name, email, password, role });

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

expect(_user.role).toBe(role);

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

it("test role is invalid", async () => {
  try {
    const name = faker.name.fullName();
    const email = faker.internet.email();
    const password = faker.internet.password(6);
    const role = faker.random.word();
    await userDao.create({ name, email, password, role });
  } catch (err) {
    expect(err.status).toBe(400);
  }
});

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