from datetime import datetime, timedelta, timezone from app.availability_service import ( get_week_boundaries, is_participant_free, ) def test_get_week_boundaries_returns_monday_to_friday(): wednesday = datetime(2026, 1, 7, 12, 0, 0, tzinfo=timezone.utc) monday, friday = get_week_boundaries(wednesday) assert monday.weekday() == 0 assert friday.weekday() == 4 assert monday.hour == 0 assert friday.hour == 23 def test_get_week_boundaries_monday_input(): monday_input = datetime(2026, 1, 5, 12, 0, 0, tzinfo=timezone.utc) monday, friday = get_week_boundaries(monday_input) assert monday.day == 5 assert friday.day == 9 def test_is_participant_free_no_blocks(): slot_start = datetime(2026, 1, 6, 10, 0, 0, tzinfo=timezone.utc) slot_end = datetime(2026, 1, 6, 11, 0, 0, tzinfo=timezone.utc) assert is_participant_free([], slot_start, slot_end) is True def test_is_participant_free_with_non_overlapping_block(): slot_start = datetime(2026, 1, 6, 10, 0, 0, tzinfo=timezone.utc) slot_end = datetime(2026, 1, 6, 11, 0, 0, tzinfo=timezone.utc) busy_blocks = [ ( datetime(2026, 1, 6, 14, 0, 0, tzinfo=timezone.utc), datetime(2026, 1, 6, 15, 0, 0, tzinfo=timezone.utc), ) ] assert is_participant_free(busy_blocks, slot_start, slot_end) is True def test_is_participant_busy_with_overlapping_block(): slot_start = datetime(2026, 1, 6, 10, 0, 0, tzinfo=timezone.utc) slot_end = datetime(2026, 1, 6, 11, 0, 0, tzinfo=timezone.utc) busy_blocks = [ ( datetime(2026, 1, 6, 10, 30, 0, tzinfo=timezone.utc), datetime(2026, 1, 6, 11, 30, 0, tzinfo=timezone.utc), ) ] assert is_participant_free(busy_blocks, slot_start, slot_end) is False def test_is_participant_busy_with_containing_block(): slot_start = datetime(2026, 1, 6, 10, 0, 0, tzinfo=timezone.utc) slot_end = datetime(2026, 1, 6, 11, 0, 0, tzinfo=timezone.utc) busy_blocks = [ ( datetime(2026, 1, 6, 9, 0, 0, tzinfo=timezone.utc), datetime(2026, 1, 6, 12, 0, 0, tzinfo=timezone.utc), ) ] assert is_participant_free(busy_blocks, slot_start, slot_end) is False