In this episode, we're circling back to write some comprehensive tests for our service slot generator now that the feature itself is done. The main goal here is to make sure our slot availability logic is solid and covers all the essential cases, so you'll see us writing high-level feature tests that hit the database and walk through the typical usage scenarios.
We start by verifying that our service correctly lists available time slots for a given day. We pay special attention to setting up a controlled environment using Carbon to fix the test date, so our tests aren't flaky due to the real current date.
From there, we expand to check listing slots across multiple days, ensuring that the slot generator accurately returns expected results for a range of dates. We use expectations and Pest's test helpers to make our assertions clean but occasionally have to dive into the data to check slot counts and specific dates.
Next, we look at some more nuanced business logic: making sure booked appointments are excluded from availability (so no double bookings), and that cancelled appointments are ignored, meaning those time slots are opened back up. We manipulate employee appointment data as needed to fully test these edge cases.
We also make sure the system can handle multiple employees being available for the same service. In the tests, we create several employees and check that each available slot reflects both employees correctly.
Throughout, we keep our setup DRY by reusing common parts and making tweaks where needed for each scenario. The end result is a robust set of feature tests that interact with our real slot generator and underlying classes, giving us confidence that changes won't break business-critical scheduling logic.
By the end of this video, you'll not only see what kinds of tests are important for a service availability feature like this, but also some practical Pest testing patterns (including working with collections, custom data structures, and date/time logic) that you can use in your own projects.