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 31, 2024
1 parent 8f1e05c commit c6fc4c3
Show file tree
Hide file tree
Showing 5 changed files with 31 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
1 change: 1 addition & 0 deletions benefits/enrollment/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ def index(request):
enrollment_method=models.EnrollmentMethods.DIGITAL,
verified_by=flow.eligibility_verifier,
expiration_datetime=expiry,
extra_claims=extra_claims,
)
event.save()
extra_claims = session.oauth_extra_claims(
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_extra_claims(mocker):
return mocker.patch("benefits.core.session.oauth_extra_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_extra_claims,
):
mocked_session_oauth_extra_claims.return_value = ["claim_1", "claim_2"]
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_1, claim_2",
)

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_extra_claims,
):
mocked_session_oauth_extra_claims.return_value = ["claim_1", "claim_2"]
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_1, claim_2",
)

assert response.status_code == 200
Expand Down

0 comments on commit c6fc4c3

Please sign in to comment.