From 9dd5b0edf086870a488868d4276c3c6e212325b7 Mon Sep 17 00:00:00 2001 From: Luis Alvergue Date: Wed, 30 Oct 2024 00:00:21 +0000 Subject: [PATCH] feat(analytics): add the returned extra claims field to EnrollmentEvent --- .../0030_enrollmentevent_extra_claims.py | 18 ++++++++++++++++++ benefits/core/models.py | 1 + benefits/enrollment/views.py | 1 + tests/pytest/conftest.py | 5 +++++ tests/pytest/enrollment/test_views.py | 6 ++++++ 5 files changed, 31 insertions(+) create mode 100644 benefits/core/migrations/0030_enrollmentevent_extra_claims.py diff --git a/benefits/core/migrations/0030_enrollmentevent_extra_claims.py b/benefits/core/migrations/0030_enrollmentevent_extra_claims.py new file mode 100644 index 0000000000..4f3a54308f --- /dev/null +++ b/benefits/core/migrations/0030_enrollmentevent_extra_claims.py @@ -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), + ), + ] diff --git a/benefits/core/models.py b/benefits/core/models.py index f6e5678e97..3b8b930797 100644 --- a/benefits/core/models.py +++ b/benefits/core/models.py @@ -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) diff --git a/benefits/enrollment/views.py b/benefits/enrollment/views.py index ddcb936da1..305edea0fa 100644 --- a/benefits/enrollment/views.py +++ b/benefits/enrollment/views.py @@ -81,6 +81,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(request) diff --git a/tests/pytest/conftest.py b/tests/pytest/conftest.py index a1ac35ab70..fbee1add68 100644 --- a/tests/pytest/conftest.py +++ b/tests/pytest/conftest.py @@ -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") diff --git a/tests/pytest/enrollment/test_views.py b/tests/pytest/enrollment/test_views.py index 81b027aa03..bc620f12ba 100644 --- a/tests/pytest/enrollment/test_views.py +++ b/tests/pytest/enrollment/test_views.py @@ -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") @@ -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 @@ -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") @@ -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