diff --git a/tests/pytest/core/test_analytics.py b/tests/pytest/core/test_analytics.py index 49065c5572..c03a57dae9 100644 --- a/tests/pytest/core/test_analytics.py +++ b/tests/pytest/core/test_analytics.py @@ -1,7 +1,7 @@ import pytest import benefits.core.analytics -from benefits.core.analytics import Event +from benefits.core.analytics import Event, ViewedPageEvent @pytest.mark.django_db @@ -80,3 +80,49 @@ def test_Event_update_user_properties(app_request): assert key in event.user_properties assert event.user_properties[key] == value + + +@pytest.mark.django_db +def test_ViewedPageEvent_sets_default_event_properties(app_request, mocker): + update_spy = mocker.spy(ViewedPageEvent, "update_event_properties") + + ViewedPageEvent(app_request) + + utm_codes = ["utm_campaign", "utm_source", "utm_medium", "utm_content", "utm_id"] + for utm_code in utm_codes: + assert utm_code in update_spy.call_args.kwargs + assert update_spy.call_args.kwargs.get(utm_code) is None + + +@pytest.mark.django_db +def test_ViewedPageEvent_sets_default_user_properties(app_request, mocker): + update_spy = mocker.spy(ViewedPageEvent, "update_user_properties") + + ViewedPageEvent(app_request) + + utm_codes = ["utm_campaign", "utm_source", "utm_medium", "utm_content", "utm_id"] + for utm_code in utm_codes: + assert utm_code in update_spy.call_args.kwargs + assert update_spy.call_args.kwargs.get(utm_code) is None + + +@pytest.mark.django_db +def test_ViewedPageEvent_update_event_properties(app_request): + key, value = "utm_campaign", "Transit" + event = ViewedPageEvent(app_request) + + event.update_event_properties(**{key: value}) + + assert key in event.event_properties + assert event.event_properties[key] == value + + +@pytest.mark.django_db +def test_ViewedPageEvent_update_user_properties(app_request): + key, value = "utm_campaign", "Transit" + event = ViewedPageEvent(app_request) + + event.update_user_properties(**{key: value}) + + assert key in event.user_properties + assert event.user_properties[key] == value