Skip to content

Commit 40421ec

Browse files
committed
✅ Add tests for no alerts triggered
1 parent 6e23103 commit 40421ec

6 files changed

Lines changed: 1099 additions & 3 deletions

File tree

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.6.0
1+
1.6.1

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "hbnmigration",
3-
"version": "1.6.0",
3+
"version": "1.6.1",
44
"private": true,
55
"description": "HBN data migration monitoring infrastructure with Python and Node.js services",
66
"workspaces": [

python_jobs/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.6.0
1+
1.6.1

python_jobs/src/tests/test_alerts_curious_to_redcap.py

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,3 +622,125 @@ def test_response_index_reverse_lookup(field_name, choices, expected):
622622
)
623623
result = response_index_reverse_lookup(row)
624624
assert result == expected
625+
626+
627+
# ============================================================================
628+
# Tests - fetch_alerts_metadata
629+
# ============================================================================
630+
631+
632+
def test_fetch_alerts_metadata_called_in_process_alerts(
633+
mock_alerts_dependencies, redcap_alerts_metadata
634+
):
635+
"""Test that fetch_alerts_metadata is called during alert processing."""
636+
setup_standard_alert_mocks(mock_alerts_dependencies, redcap_alerts_metadata)
637+
alert_df = create_alert_df(["MRN12345"], ["alerts_parent_baseline_1"], ["yes"])
638+
639+
process_alerts_for_redcap(alert_df)
640+
641+
# The fetch_alerts_metadata should be called (it's the imported function)
642+
assert mock_alerts_dependencies["fetch_metadata"].called
643+
644+
645+
# ============================================================================
646+
# Tests - Parametrized Parse Alert Tests
647+
# ============================================================================
648+
649+
650+
@pytest.mark.parametrize(
651+
"message,expected_item",
652+
[
653+
(
654+
'Red: "Yes" - Difficulty concentrating parent_baseline',
655+
"alerts_parent_baseline_difficulty_concentrating",
656+
),
657+
(
658+
'Yellow: "No" - Sleep issues child_followup',
659+
"alerts_child_followup_sleep_issues",
660+
),
661+
(
662+
'Green: "Sometimes" - Mood changes parent_followup',
663+
"alerts_parent_followup_mood_changes",
664+
),
665+
],
666+
ids=["red_parent", "yellow_child", "green_parent"],
667+
)
668+
def test_parse_alert_various_colors_and_items(
669+
sample_curious_alert, message, expected_item
670+
):
671+
"""Test parse_alert with various color and item combinations."""
672+
alert = sample_curious_alert.copy()
673+
alert["message"] = message
674+
result = parse_alert(alert)
675+
676+
assert not result.empty
677+
assert sample_curious_alert["secretId"] in result["record"].values
678+
# Verify that an item field was created
679+
item_fields = result[result["field_name"] != "mrn"]
680+
assert len(item_fields) > 0
681+
682+
683+
# ============================================================================
684+
# Tests - Parametrized Process Alerts Tests
685+
# ============================================================================
686+
687+
688+
@pytest.mark.parametrize(
689+
"records,field_names,expected_summary",
690+
[
691+
(
692+
["001", "001"],
693+
["alerts_parent_baseline_1", "alerts_parent_baseline_2"],
694+
"parent_baseline_alerts",
695+
),
696+
(
697+
["003"],
698+
["alerts_parent_baseline_1"],
699+
"parent_baseline_alerts",
700+
),
701+
],
702+
ids=["parent_baseline", "single_record"],
703+
)
704+
def test_process_alerts_creates_summary_fields(
705+
mock_alerts_dependencies,
706+
redcap_alerts_metadata,
707+
records,
708+
field_names,
709+
expected_summary,
710+
):
711+
"""Test that process_alerts creates appropriate summary fields."""
712+
setup_standard_alert_mocks(mock_alerts_dependencies, redcap_alerts_metadata)
713+
alert_df = create_alert_df(records, field_names, ["yes"] * len(field_names))
714+
715+
result = process_alerts_for_redcap(alert_df)
716+
717+
# Should have summary field if metadata contains the instrument
718+
summary_rows = result[result["field_name"] == expected_summary]
719+
assert len(summary_rows) > 0
720+
721+
722+
# ============================================================================
723+
# Tests - Parametrized Push Alerts Tests
724+
# ============================================================================
725+
726+
727+
@pytest.mark.parametrize(
728+
"records,values",
729+
[
730+
(["001", "001"], ["yes", "no"]),
731+
(["002"], ["1"]),
732+
(["003", "004"], ["yes", "yes"]),
733+
],
734+
ids=["mixed_yes_no", "numeric", "all_yes"],
735+
)
736+
def test_push_alerts_various_values(mock_alerts_dependencies, records, values):
737+
"""Test push_alerts_to_redcap with various alert values."""
738+
alert_df = create_alert_df(
739+
records, ["alerts_parent_baseline_1"] * len(records), values
740+
)
741+
push_alerts_to_redcap(alert_df)
742+
743+
push_mock = mock_alerts_dependencies["push"]
744+
assert push_mock.called
745+
pushed_data = push_mock.call_args[0][0]
746+
assert len(pushed_data) == len(records)

0 commit comments

Comments
 (0)