Skip to content

Commit

Permalink
feat(analytics): add the extra claims that were verified to analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
lalver1 committed Oct 29, 2024
1 parent c404a88 commit 5edf0c9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
9 changes: 7 additions & 2 deletions benefits/enrollment/analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
The enrollment application: analytics implementation.
"""

from benefits.core import analytics as core, models
from benefits.core import analytics as core, models, session


class ReturnedEnrollmentEvent(core.Event):
Expand All @@ -11,7 +11,12 @@ class ReturnedEnrollmentEvent(core.Event):
def __init__(self, request, status, error=None, enrollment_group=None, enrollment_method=models.EnrollmentMethods.DIGITAL):
super().__init__(request, "returned enrollment", enrollment_method)
if str(status).lower() in ("error", "retry", "success"):
self.update_event_properties(status=status, error=error)
oauth_claims = session.oauth_claims(request)
if oauth_claims is not None:
extra_claims = oauth_claims[1:]
self.update_event_properties(status=status, error=error, extra_claims=extra_claims)
else:
self.update_event_properties(status=status, error=error)
if enrollment_group is not None:
self.update_event_properties(enrollment_group=enrollment_group)

Expand Down
20 changes: 19 additions & 1 deletion tests/pytest/enrollment/test_analytics.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
import pytest

from benefits.enrollment.analytics import FailedAccessTokenRequestEvent
from benefits.enrollment.analytics import FailedAccessTokenRequestEvent, ReturnedEnrollmentEvent


@pytest.mark.django_db
def test_FailedAccessTokenRequestEvent_sets_status_code(app_request):
event = FailedAccessTokenRequestEvent(app_request, 500)

assert event.event_properties["status_code"] == 500


@pytest.mark.django_db
def test_ReturnedEnrollmentEvent_without_error(app_request, mocker):

key1 = "enrollment_flows"
key2 = "extra_claims"
mock_flow = mocker.Mock()
mock_flow.system_name = "flow_1"
mocker.patch("benefits.core.session.flow", return_value=mock_flow)

mock_claims = ["eligibility_claim", "extra_claim"]
mocker.patch("benefits.core.session.oauth_claims", return_value=mock_claims)

event = ReturnedEnrollmentEvent(app_request, status="success")
assert "error_code" not in event.event_properties
assert key1 in event.event_properties
assert key2 in event.event_properties

0 comments on commit 5edf0c9

Please sign in to comment.