Skip to content

Commit

Permalink
Fix date range logic and enhance tests for booking API.
Browse files Browse the repository at this point in the history
Update the `to_date` condition in availability logic to include the end date, fixing a missing day issue. Enhance test coverage to validate that all days in the range are accounted for and their slot statistics are consistent.
  • Loading branch information
rithviknishad committed Jan 31, 2025
1 parent 9be535f commit 0ecaeb2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion care/emr/api/viewsets/scheduling/availability.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def availability_stats(self, request, *args, **kwargs):
days = {}
response_days = {}
day = request_data.from_date
while day < request_data.to_date:
while day <= request_data.to_date:
days[day] = {"total_slots": 0, "booked_slots": 0}
response_days[str(day)] = {"total_slots": 0, "booked_slots": 0}
day += timedelta(days=1)
Expand Down
17 changes: 15 additions & 2 deletions care/emr/tests/test_booking_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -867,16 +867,29 @@ def test_availability_heatmap_slots_same_as_get_slots_for_day_without_exceptions
self,
):
"""Availability heatmap slot counts should match individual day slot counts when there are no exceptions."""
from_date = datetime.now(UTC).date()
end_date = from_date + timedelta(days=7)
data = {
"user": self.user.external_id,
"from_date": datetime.now(UTC).strftime("%Y-%m-%d"),
"to_date": (datetime.now(UTC) + timedelta(days=7)).strftime("%Y-%m-%d"),
"from_date": from_date.strftime("%Y-%m-%d"),
"to_date": end_date.strftime("%Y-%m-%d"),
}
response = self.client.post(
self._get_availability_stats_url(), data, format="json"
)
self.assertEqual(response.status_code, 200)

# verify all days are present
date = from_date
while date <= end_date:
self.assertContains(
response,
status_code=200,
text=date.strftime("%Y-%m-%d"),
)
date += timedelta(days=1)

# verify booked slots and total slots from get slots for day matches heatmap
for day, slot_stats in response.data.items():
data = {"user": self.user.external_id, "day": day}
response = self.client.post(
Expand Down

0 comments on commit 0ecaeb2

Please sign in to comment.