nomadro/apps/api/tests/test_coffee_scheduling.py
Eric 499f2d3e26 Ship coffeechat scheduling, notify PB access, and social/admin UI polish for .com.
Document the 2026-11-05 UI/UX upgrade and keep roster/live gates aligned with face-check and presence.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-05 18:19:37 +08:00

51 lines
2.7 KiB
Python

from datetime import datetime, timezone
import unittest
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'services'))
from coffee_svc.scheduling import available_times
class CoffeeSchedulingTests(unittest.TestCase):
def setUp(self):
self.schedule = {
'timezone': 'America/New_York',
'availability': [{'days': ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'], 'startTime': 9 * 60, 'endTime': 12 * 60}],
}
self.event = {'active': True, 'length_minutes': 30, 'slot_interval': 30}
def test_uses_host_local_weekday_and_utc_output(self):
result = available_times('2026-11-09', self.schedule, self.event, [], datetime(2026, 11, 1, tzinfo=timezone.utc))
self.assertEqual(result[0]['local'], '09:00')
self.assertEqual(result[0]['start'], '2026-11-09T14:00:00Z')
def test_excludes_past_and_overlapping_buffered_booking(self):
bookings = [{'status': 'accepted', 'start_utc': '2026-11-09T15:00:00Z', 'end_utc': '2026-11-09T15:30:00Z'}]
event = {**self.event, 'buffer_before': 15, 'buffer_after': 15}
result = available_times('2026-11-09', self.schedule, event, bookings, datetime(2026, 11, 9, 13, 45, tzinfo=timezone.utc))
self.assertNotIn('2026-11-09T15:00:00Z', {row['start'] for row in result})
self.assertNotIn('2026-11-09T14:30:00Z', {row['start'] for row in result})
self.assertNotIn('2026-11-09T15:30:00Z', {row['start'] for row in result})
self.assertIn('2026-11-09T16:00:00Z', {row['start'] for row in result})
def test_inactive_and_wrong_weekday_have_no_slots(self):
self.assertEqual(available_times('2026-11-08', self.schedule, self.event, []), [])
self.assertEqual(available_times('2026-11-09', self.schedule, {**self.event, 'active': False}, []), [])
def test_dst_spring_forward_skips_nonexistent_wall_time(self):
schedule = {'timezone': 'America/New_York', 'availability': [{'days': ['Sunday'], 'startTime': 1 * 60, 'endTime': 4 * 60}]}
event = {'active': True, 'length_minutes': 30, 'slot_interval': 30}
result = available_times('2026-03-08', schedule, event, [], datetime(2026, 1, 1, tzinfo=timezone.utc))
self.assertNotIn('02:00', {row['local'] for row in result})
def test_duplicate_windows_are_deduplicated(self):
schedule = {**self.schedule, 'availability': self.schedule['availability'] * 2}
result = available_times('2026-11-09', schedule, self.event, [], datetime(2026, 1, 1, tzinfo=timezone.utc))
self.assertEqual(len(result), len({row['start'] for row in result}))
if __name__ == '__main__':
unittest.main()