In this episode, we dive into how to determine which channels (like email or Slack) a notification should be sent through, based on a user's preferences. We aren't going to actually set up sending emails or Slack messages, but we'll set everything up so our application can grab the right channels for each user when a notification (like 'Project Created') is triggered.
First, we clean up some naming and make sure we're using 'mail' everywhere instead of 'email' so things are consistent in our database and code. Next, we explore how to store notification types and how they link up with user preferences, using a method that will map notification types to the database. This allows us to fetch each user's selected channels for a given notification (like 'mail' and 'slack'), instead of hardcoding them.
After that, we write a test to make sure this works: we attach some notification preferences to a test user, trigger a notification, and check that it's sent via the correct channels. We also see a couple of ways to test this, both by faking the notification and directly asserting that our code is returning the right channels for the user.
By the end, you'll have a flexible setup where the notification channels are determined by user preferences, and you can confidently test that they're working as expected.