In this episode, we focus on writing tests for the schedule availability functionality that we previously built. We kick off by outlining a series of tests covering different scenarios, like listing correct employee availability, handling different daily schedule times, not showing times for scheduled exclusions (like holidays or breaks), and ensuring we only show availability starting from the current time plus an hour ahead.
You'll see how to use test helpers (like setTestNow
in Carbon) to control time inside your tests, which is essential when dealing with schedules. We walk through creating employees and their schedules using factories, tweaking daily start and end times, and injecting services with different durations. As we write the tests, we also make adjustments in our codebase, like making sure migrations are handled correctly and returning the right data structure from our schedule availability class.
We also cover:
By the end, you’ll have a solid understanding of how to structure and write comprehensive tests for availability logic, learn useful testing practices for time-based features, and get comfortable iterating over days and periods in your assertions.