In this episode, we dive into testing the login flow of our application using the PEST testing framework. If you haven't used PEST before, don't worry! We walk through how to install and set it up from scratch.
We kick things off by listing what needs to be tested in the login process: checking that the email is valid, ensuring the email exists in the database, and verifying that a login email is actually sent to the user. After the initial setup, we configure our testing environment to use an in-memory SQLite database so that our tests run quickly and don't interfere with real data.
With the basics out of the way, we generate our first PEST feature tests. The first two tests are all about validation: making sure only valid email addresses get accepted and that the user actually exists in the database before we try sending anything. Along the way, you'll see some tips about making your tests cleaner and easier to read, thanks to PEST's higher-order features.
The last part, and maybe the most important, is confirming that a login email really gets sent out. We show you how to use Laravel's mail fakes so no real emails are sent during testing. You'll see how to check that a Magic Link email was sent to the specific user who requested it. If any part of this breaks (say, the email isn't sent to the right person), you'll catch it immediately in your tests.
By the end of this episode, you'll have a solid set of login flow tests, giving you confidence that your authentication works and that users get their login emails as expected. Next up: we'll apply some of these same ideas to the registration flow!