Exercise 1 (Testing the Login Controller)

Project Source Code

Get the project source code below, and follow along with the lesson material.

Download Project Source Code

To set up the project on your local machine, please follow the directions provided in the README.md file. If you run into any issues with running the project source code, then feel free to reach out to the author in the course's Discord channel.

This lesson preview is part of the Pain Free Mocking with Jest course and can be unlocked immediately with a \newline Pro subscription or a single-time purchase. Already have access to this course? Log in here.

This video is available to students only
Unlock This Course

Get unlimited access to Pain Free Mocking with Jest, plus 70+ \newline books, guides and courses with the \newline Pro subscription.

Thumbnail for the \newline course Pain Free Mocking with Jest
  • [00:00 - 00:09] In this lesson, we have an exercise for you to solve. You will be creating an integration test for the login route of our application .

    [00:10 - 00:21] We'll cover both the happy path and the sad path scenarios. To start, create an integration test file for the login route.

    [00:22 - 00:38] Remember, the login route expects an email and password in the request body. If the user and password are correct, the application should return a 200 status code.

    [00:39 - 00:49] Representing the happy path. If the email or password is wrong, the application will return a 400 status code representing the sad path.

    [00:50 - 00:59] In this exercise, your task is to create an integration test. You'll need to clear the database collection before each test.

    [01:00 - 01:13] Create a user with your desired email and password for the happy path scenario. And make a request to the login route with valid credentials in the act step.

    [01:14 - 01:25] For the sad path scenario, don't add any user to the database. And make a request to the login route with invalid email or password.

    [01:26 - 01:38] Finally, assert that the response status code is correct for both scenarios. Take your time to think through the steps and complete the code.

    [01:39 - 01:48] Don't forget to import the necessary modules and set up your test environment properly. I believe in your ability to solve this exercise.

    [01:49 - 02:02] Remember, practice is key to mastering integration testing. Take the time to walk through this exercise and once you're done, feel free to explore more advanced scenarios or look at the solution in the next lesson.

    [02:03 - 02:09] The more you practice, the more confidence you will become in testing your applications. You've got this.