In this episode, we first tie up a loose end from last time by making sure users can't add the same friend twice—we write a test case so that duplicate friend requests aren't created. Using PEST, we see a couple of different ways to write the assertion and learn how to use negation to make things even clearer.
Once that's sorted, we dive into the heart of the episode: implementing the ability to accept friend requests! We sketch out how the test for accepting a friend request should look, then fill in the actual functionality in the code. This involves writing an acceptFriend
method and setting up a new "accepted friends" relationship so we can check both pending and accepted friends separately.
As we go, we explore writing more robust assertions, like checking that the correct IDs show up in the list of accepted friends. Plus, there's some discussion about how we'll be able to refactor the tests later to make them even nicer to read. By the end of this episode, we've fully covered accepting friend requests and have solid tests around it. Next up—listing all your friends!