feat: full backend (untested)

This commit is contained in:
Nik L
2026-01-14 11:37:44 -05:00
parent 4a0db63a30
commit d585cf8613
32 changed files with 1317 additions and 57 deletions

View File

16
backend/tests/conftest.py Normal file
View File

@@ -0,0 +1,16 @@
import pytest
@pytest.fixture
def sample_ics():
return """BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Test//Test//EN
BEGIN:VEVENT
DTSTART:20260106T150000Z
DTEND:20260106T160000Z
SUMMARY:Meeting
UID:test-1
DTSTAMP:20260101T000000Z
END:VEVENT
END:VCALENDAR"""

View File

@@ -0,0 +1,73 @@
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

View File

@@ -0,0 +1,58 @@
import uuid
import pytest
from app.ics_service import parse_ics_to_busy_blocks
SAMPLE_ICS = """BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Test//Test//EN
BEGIN:VEVENT
DTSTART:20260106T150000Z
DTEND:20260106T160000Z
SUMMARY:Meeting
UID:test-1
DTSTAMP:20260101T000000Z
END:VEVENT
BEGIN:VEVENT
DTSTART:20260107T140000Z
DTEND:20260107T153000Z
SUMMARY:Another Meeting
UID:test-2
DTSTAMP:20260101T000000Z
END:VEVENT
END:VCALENDAR"""
def test_parse_ics_extracts_busy_blocks():
participant_id = str(uuid.uuid4())
blocks = parse_ics_to_busy_blocks(SAMPLE_ICS, participant_id)
assert len(blocks) == 2
assert all(str(b.participant_id) == participant_id for b in blocks)
def test_parse_ics_extracts_correct_times():
participant_id = str(uuid.uuid4())
blocks = parse_ics_to_busy_blocks(SAMPLE_ICS, participant_id)
sorted_blocks = sorted(blocks, key=lambda b: b.start_time)
assert sorted_blocks[0].start_time.hour == 15
assert sorted_blocks[0].end_time.hour == 16
assert sorted_blocks[1].start_time.hour == 14
assert sorted_blocks[1].end_time.hour == 15
assert sorted_blocks[1].end_time.minute == 30
def test_parse_empty_ics():
empty_ics = """BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Test//Test//EN
END:VCALENDAR"""
participant_id = str(uuid.uuid4())
blocks = parse_ics_to_busy_blocks(empty_ics, participant_id)
assert len(blocks) == 0