From b9e22766c00a1af6a656597ab95c8aac2d7fff93 Mon Sep 17 00:00:00 2001 From: OpenCode Cabillot Date: Fri, 9 Oct 2026 00:16:58 +0000 Subject: [PATCH] test: cover build_filter (participant should-clause, date ranges, combination) --- tests/test_server.py | 53 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/tests/test_server.py b/tests/test_server.py index a4c71d8..440945e 100644 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -8,6 +8,7 @@ from server import ( normalize_email_address, payload_matches_participant, format_search_result, + build_filter, ) @@ -108,3 +109,55 @@ class TestFormatSearchResult: assert result["receiver"] is None assert result["subject"] is None assert result["attachments"] == [] + + +class TestBuildFilter: + def test_no_filters_returns_none(self): + assert build_filter(None, None, None) is None + + def test_empty_strings_return_none(self): + assert build_filter("", "", "") is None + + def test_participant_filter_is_should_clause_on_sender_and_receiver(self): + f = build_filter("alice@example.com", None, None) + assert f is not None + # The date conditions list must be absent and only the participant filter present + assert len(f.must) == 1 + participant = f.must[0] + keys = [c.key for c in participant.should] + assert keys == ["sender", "receiver"] + assert all(c.match.value == "alice@example.com" for c in participant.should) + + def test_participant_normalized_before_match(self): + f = build_filter("Alice ", None, None) + should = f.must[0].should + assert all(c.match.value == "alice@example.com" for c in should) + + def test_date_range_only(self): + f = build_filter(None, "2026-01-01", "2026-06-30") + assert len(f.must) == 1 + cond = f.must[0] + assert cond.key == "date" + assert cond.range.gte is not None + assert cond.range.lte is not None + + def test_start_date_only(self): + f = build_filter(None, "2026-03-15", None) + cond = f.must[0] + assert cond.range.gte is not None + assert cond.range.lte is None + + def test_end_date_only(self): + f = build_filter(None, None, "2026-03-15") + cond = f.must[0] + assert cond.range.gte is None + assert cond.range.lte is not None + + def test_combined_participant_and_date(self): + f = build_filter("bob@example.org", "2026-01-01", "2026-12-31") + assert len(f.must) == 2 + # One is the participant should-filter, the other the date range + kinds = sorted( + "participant" if getattr(c, "should", None) else "date" for c in f.must + ) + assert kinds == ["date", "participant"]