Step 13

Update the remaining tests in auth.test.js file:

test("Return 400 when username is missing", async () => {
  const response = await request.post("/authenticate").send({
    password: "testclient",
  });
  expect(response.status).toBe(400);
});

test("Return 400 when password is missing", async () => {
  const response = await request.post("/authenticate").send({
    username: "testclient",
  });
  expect(response.status).toBe(400);
});

test("Return 403 when username is incorrect", async () => {
  const response = await request.post("/authenticate").send({
    username: "client",
    password: "testclient",
  });
  expect(response.status).toBe(403);
});

test("Return 403 when password is incorrect", async () => {
  const response = await request.post("/authenticate").send({
    username: "testclient",
    password: "client",
  });
  expect(response.status).toBe(403);
});

test("Return 200 when authentication is sucessfull", async () => {
  const response = await request.post("/authenticate").send({
    username: "testclient",
    password: "testclient",
  });
  expect(response.status).toBe(200);
});

test("Return a JWT when authentication is sucessfull", async () => {
  const response = await request.post("/authenticate").send({
    username: "testclient",
    password: "testclient",
  });
  expect(response.body.token).toBeTruthy(); // exists and non empty!
});

Rerun the tests! Observe that our coverage shows we are testing for every authenticate route handler (except for when an unexpected internal server error happens, which we should not do during unit testing).