In this episode, we dive into adding the ability for users to remove friends from their friend list. We start by setting up a feature test where we first add a friend (just to have a friend relationship to work with!), and then move on to removing that friend. Interestingly, we see that whether the friendship has been accepted or not, deleting the record works exactly the same way — it simply detaches that relationship between the two users.
We implement a new removeFriend
method, making sure it wipes out both pending requests and existing friendships. After writing the test, we run it and ensure it passes, confirming the implementation behaves as expected. As a small experiment, we also test removing a non-accepted friend request, and it works perfectly!
Wrapping up, we realize that with this method, we've now completed all the core user-related functionality for managing friends. Up next, we'll move away from backend logic and start working on the UI to make our app more interactive.