In this episode, we're going to streamline our testing process for mention notifications by writing automated tests, rather than manually checking our inboxes every time. We start by ensuring that when a comment includes a mention, the correct users actually get a notification. We use fake notifications in our tests so we can check what would be sent without actually firing off real emails or notifications.
Next, we tackle an important edge case: making sure that notifications aren't sent when a comment is edited to mention a different user. This helps us avoid spamming people with notifications just because someone updated their comment. We set up a simple test to verify that notifications are only sent when a comment is first created, and not on subsequent edits.
Throughout the episode, we walk through setting up users, creating comments, and updating them — all while leveraging Laravel's test helpers like Notification::fake()
and assertions to check the right notifications go to the right people, and only once. By the end, our mention notification logic is well-covered by tests, so we can be confident things will keep working as expected!