Booking overlap test cases: double booking checks
A booking system has one rule that matters more than any field check: the same resource cannot be taken twice at the same moment. The rule is one comparison in code, and it tends to break in the same few places. This page lists test cases for each of them, with expected results.
The examples use meeting rooms and times of day, but the cases carry over to hotel nights and appointments. For the basic set on a single REST endpoint (back to back, starts inside, covers completely) see REST API test cases; the sections below go past it.
The rule and its usual mistakes
Two bookings of one resource overlap when each starts before the other ends:
newStart < oldEnd && oldStart < newEnd. Overlap bugs usually come from a
line that looks close to it and passes the obvious test:
| Code | Passes | Fails on |
|---|---|---|
<= instead of < | Any real overlap | 10:00–11:00 next to 11:00–12:00 is rejected |
| Only "new start is inside an old booking" | 10:30–11:30 against 10:00–11:00 | 09:30–10:30 and 09:00–12:00 are accepted |
| Only "new start or new end is inside" | Partial overlaps on both sides | 09:00–12:00 covers the old booking and is accepted |
| Compares against the first booking found | A room with one booking | The conflict is with the second booking of the day |
| Equal start times treated as "no overlap" | Different starts | An exact copy of an existing booking is accepted |
The fourth row needs a room with at least three bookings on the same day, and the conflict should be with the last one created.
Which bookings take part in the check
The check also depends on which existing bookings it reads. Set up each of these states on the slot, then try to book it:
| Existing booking on the slot | Expected for a new booking |
|---|---|
| Cancelled | Accepted |
| Deleted, if the system keeps deleted rows | Accepted |
| Pending or on hold (payment not finished) | Rejected while the hold lasts |
| Hold that has expired | Accepted |
| Belongs to another user | Rejected, and the message does not show that user's details |
| Same time, another room or another branch | Accepted |
| Same room id in another account or tenant | Accepted, if rooms are separate per account |
Editing adds one more case. Moving a booking within its own time, for example from 10:00–11:00 to 10:00–11:30, must not conflict with itself. A check that forgets to exclude the booking being edited rejects every extension. A check that excludes it by the wrong id lets an edit land on someone else's slot.
Capacity greater than one
A room with two desks, a class with ten seats or a hotel with five rooms of one type has a capacity. The rule becomes "at no moment more than N bookings". Counting how many bookings overlap the new one gives a different answer, as the first row shows.
| Capacity 2, existing | New | Most at one moment | Expected |
|---|---|---|---|
| 09:00–10:00, 10:00–11:00 | 09:30–10:30 | 2 | Accepted |
| 09:00–10:00, 09:30–10:30 | 09:45–09:50 | 3 | Rejected |
| 09:00–10:00, 09:00–10:00 | 10:00–10:15 | 2 | Accepted |
In the first row the new booking overlaps two bookings, but those two never meet, so no more than two are in use at any moment. Code that counts overlapping bookings gets 2, compares it with the capacity and rejects a free slot. To find the opposite error, fill the capacity and then try one more booking in the busiest minute. Check the edit path too: shortening one booking should free capacity, and extending one should be checked against the full count.
Buffers between bookings
Many systems keep time free after a booking for cleaning or changeover. With a 15-minute buffer and an existing booking 10:00–11:00, a new one-hour booking:
| New start | Expected |
|---|---|
| 11:00 | Rejected |
| 11:10 | Rejected |
| 11:15 | Accepted |
| 08:45 (ends 09:45) | Accepted |
| 08:50 (ends 09:50) | Rejected |
The last two rows test the buffer before the booking. A common shortcut adds the buffer only to the end of the old booking, so a new booking that ends inside the buffer before it is accepted. Ask whether the buffer belongs to each booking or to the gap between them, and whether it counts at opening and closing time.
Bookings that cross midnight
A booking from 22:00 to 02:00, stored as two times of day without dates, has an end smaller than its start. The standard comparison then gives wrong answers in both directions:
| Existing | New | Real overlap | Compared as times only |
|---|---|---|---|
| 22:00–02:00 | 23:00–23:30 | Yes | No conflict |
| 22:00–02:00 | 01:00–03:00 the next day | Yes, 01:00–02:00 | No conflict |
Test what the system does with a booking that ends after midnight: rejects it, stores it as two days, or stores it with full dates. Then try both rows above, and a booking that starts at 00:00 on the next day. For hotel nights the same question is whether check-out day counts as booked: the usual rule is that a stay from the 10th to the 12th leaves the 12th free for the next guest's arrival.
Daylight saving time
On November 7, 2027 New York clocks go back from 02:00 to 01:00, so 01:00–02:00 happens twice. A booking from 01:00 to 01:45 before the change and one from 01:15 to 01:45 after it look like an overlap on the wall clock. In UTC they are 05:00–05:45 and 06:15–06:45, half an hour apart.
| Test (New York, 2027) | Expected |
|---|---|
| The two bookings above on November 7 | Accepted, if the system stores moments; the app says which 01:15 it means |
| Booking 01:30–03:30 on March 14 | Takes 1 hour, since 02:00–03:00 does not exist that night |
| Booking at 02:30 on March 14 | Rejected or moved, with a message |
| Room in New York, user in Berlin, March 14–28 | The overlap is decided in the room's zone; the zones are 5 hours apart, not 6 |
More cases for time zones and clock changes are in date and time testing.
Two requests at the same moment
A server that reads existing bookings, checks for overlap and then inserts can accept two requests for the same slot if they arrive within a few milliseconds. Each one checks before the other has saved. From a shell:
for i in 1 2 3 4 5; do
curl -s -o /dev/null -w "%{http_code}\n" -X POST "$API/bookings" \
-H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
-d '{"room":"r1","date":"2027-03-02","start":"10:00","end":"11:00"}' &
done; wait
Expected: one success and four conflicts, then a list of bookings with exactly one for the slot. Run it several times, since a race does not show up on every run. Repeat with two different users, and with two overlapping but not equal slots (10:00–11:00 and 10:30–11:30), because a unique index on the start time stops only exact copies. In a browser the same test is a double click on the submit button; double submit testing covers that side.
Recurring bookings
A weekly series every Monday from January 4, 2027 for six weeks ends on February 8. Book one of the middle Mondays, say January 25, for someone else first, then create the series:
- The whole series is rejected, or the free dates are booked and the taken one is skipped. Either can be right; the app should say which and name the date in the message.
- No partial series is left behind after an error.
- Editing the time of the whole series is checked against every date, not only the first.
- Cancelling one date of the series frees only that date.
- A series that crosses the March daylight saving change keeps its local time.
What the user sees
A calendar or a list of free slots runs its own query, and it can disagree with the check on save. For each case above compare three answers: the slot as shown on the page, the result of booking it, and the slot as shown after reload. A slot shown as free that fails on save, or one shown as taken that the API accepts, is a bug even when the overlap check itself is correct. The same goes for a check done only in the page: send the request straight to the API with a taken slot and expect a conflict.
The conflict message should name the room and the time it collides with, and keep the user's input. Status code for an API: 409 Conflict is the usual choice; 400 or 500 for a taken slot is worth a report.
Open the API exercise
More guides: REST API test cases · date and time testing · all guides