Skip to content

Commit

Permalink
feat(analytics): add the returned extra claims field to EnrollmentEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
lalver1 committed Oct 30, 2024
1 parent 43492c6 commit 727a4c1
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 0 deletions.
18 changes: 18 additions & 0 deletions benefits/core/migrations/0030_enrollmentevent_extra_claims.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.1.2 on 2024-10-29 22:11

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("core", "0029_add_extra_claims"),
]

operations = [
migrations.AddField(
model_name="enrollmentevent",
name="extra_claims",
field=models.TextField(blank=True, null=True),
),
]
1 change: 1 addition & 0 deletions benefits/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,7 @@ class EnrollmentEvent(models.Model):
verified_by = models.TextField()
enrollment_datetime = models.DateTimeField(default=timezone.now)
expiration_datetime = models.DateTimeField(blank=True, null=True)
extra_claims = models.TextField(blank=True, null=True)

def __str__(self):
dt = timezone.localtime(self.enrollment_datetime)
Expand Down
2 changes: 2 additions & 0 deletions benefits/enrollment/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,14 @@ def index(request):
agency = session.agency(request)
flow = session.flow(request)
expiry = session.enrollment_expiry(request)
extra_claims = ", ".join(session.oauth_extra_claims(request))
event = models.EnrollmentEvent.objects.create(
transit_agency=agency,
enrollment_flow=flow,
enrollment_method=models.EnrollmentMethods.DIGITAL,
verified_by=flow.eligibility_verifier,
expiration_datetime=expiry,
extra_claims=extra_claims,
)
event.save()
analytics.returned_success(request, flow.group_id)
Expand Down
5 changes: 5 additions & 0 deletions tests/pytest/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,3 +274,8 @@ def mocked_session_reset(mocker):
@pytest.fixture
def mocked_session_update(mocker):
return mocker.patch("benefits.core.session.update")


@pytest.fixture
def mocked_session_oauth_claims(mocker):
return mocker.patch("benefits.core.session.oauth_claims")
6 changes: 6 additions & 0 deletions tests/pytest/enrollment/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,9 @@ def test_index_eligible_post_valid_form_success_claims(
mocked_analytics_module,
model_TransitAgency,
model_EnrollmentFlow_with_scope_and_claim,
mocked_session_oauth_claims,
):
mocked_session_oauth_claims.return_value = ["claim_1", "claim_2", "claim_3"]
mocker.patch("benefits.enrollment.views.enroll", return_value=(Status.SUCCESS, None))
spy = mocker.spy(benefits.enrollment.views.models.EnrollmentEvent.objects, "create")

Expand All @@ -318,6 +320,7 @@ def test_index_eligible_post_valid_form_success_claims(
enrollment_method=models.EnrollmentMethods.DIGITAL,
verified_by=model_EnrollmentFlow_with_scope_and_claim.claims_provider.client_name,
expiration_datetime=None,
extra_claims="claim_2, claim_3",
)

assert response.status_code == 200
Expand All @@ -335,7 +338,9 @@ def test_index_eligible_post_valid_form_success_eligibility_api(
mocked_analytics_module,
model_TransitAgency,
model_EnrollmentFlow_with_eligibility_api,
mocked_session_oauth_claims,
):
mocked_session_oauth_claims.return_value = ["claim_1", "claim_2", "claim_3"]
mocker.patch("benefits.enrollment.views.enroll", return_value=(Status.SUCCESS, None))
spy = mocker.spy(benefits.enrollment.views.models.EnrollmentEvent.objects, "create")

Expand All @@ -348,6 +353,7 @@ def test_index_eligible_post_valid_form_success_eligibility_api(
enrollment_method=models.EnrollmentMethods.DIGITAL,
verified_by=model_EnrollmentFlow_with_eligibility_api.eligibility_api_url,
expiration_datetime=None,
extra_claims="claim_2, claim_3",
)

assert response.status_code == 200
Expand Down

0 comments on commit 727a4c1

Please sign in to comment.