In this episode, we dive into testing the registration flow of our application. We kick things off by setting up a new test using Pest, and borrowing some boilerplate from our login tests to speed things up, like using the RefreshDatabase
trait to ensure a clean slate for each test.
We run through the main types of validation that the registration form needs: checking if the email is valid, making sure a name is provided, and verifying the email hasn't already been used. For the duplicate email test, we set up a user in the database first, then attempt to register with the same email to see if we get the expected error.
Then, we move on to the core registration functionality – making sure a real user can be successfully registered. We post valid registration data and use assertions to confirm that the new user's data shows up in the database. We also double-check that our app sends a magic login link via email when someone registers (using Laravel's mail fakes for testing).
Throughout the process, we run and re-run our tests to confirm everything's working. By the end of the video, we've got solid test coverage for the registration flow, so we can feel good knowing users can sign up and get their magic login link, and that all the basic validation is enforced.