Skip to content

Commit

Permalink
refactor(enrollment): send success analytics event in POST back
Browse files Browse the repository at this point in the history
prevent sending false positive events if the success view is requested
directly

this aligns with where error events are sent
  • Loading branch information
thekaveman committed Sep 13, 2024
1 parent d61d81b commit ac1f54f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
2 changes: 1 addition & 1 deletion benefits/enrollment/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def index(request):
expiration_datetime=expiry,
)
event.save()
analytics.returned_success(request, flow.group_id)
return success(request)

case Status.SYSTEM_ERROR:
Expand Down Expand Up @@ -181,6 +182,5 @@ def success(request):
# if they click the logout button, they are taken to the new route
session.update(request, origin=reverse(routes.LOGGED_OUT))

analytics.returned_success(request, flow.group_id)
context = {"redirect_to": request.path}
return TemplateResponse(request, flow.enrollment_success_template, context)
11 changes: 3 additions & 8 deletions tests/pytest/enrollment/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ def test_success_no_flow(client):

@pytest.mark.django_db
@pytest.mark.usefixtures("mocked_session_flow_uses_claims_verification", "mocked_session_eligible")
def test_success_authentication_logged_in(mocker, client, model_TransitAgency, model_EnrollmentFlow, mocked_analytics_module):
def test_success_authentication_logged_in(mocker, client, model_TransitAgency, model_EnrollmentFlow):
mock_session = mocker.patch("benefits.enrollment.views.session")
mock_session.logged_in.return_value = True
mock_session.agency.return_value = model_TransitAgency
Expand All @@ -473,14 +473,11 @@ def test_success_authentication_logged_in(mocker, client, model_TransitAgency, m
assert response.status_code == 200
assert response.template_name == model_EnrollmentFlow.enrollment_success_template
assert {"origin": reverse(routes.LOGGED_OUT)} in mock_session.update.call_args
mocked_analytics_module.returned_success.assert_called_once()


@pytest.mark.django_db
@pytest.mark.usefixtures("mocked_session_flow_uses_claims_verification", "mocked_session_eligible")
def test_success_authentication_not_logged_in(
mocker, client, model_TransitAgency, model_EnrollmentFlow, mocked_analytics_module
):
def test_success_authentication_not_logged_in(mocker, client, model_TransitAgency, model_EnrollmentFlow):
mock_session = mocker.patch("benefits.enrollment.views.session")
mock_session.logged_in.return_value = False
mock_session.agency.return_value = model_TransitAgency
Expand All @@ -491,17 +488,15 @@ def test_success_authentication_not_logged_in(

assert response.status_code == 200
assert response.template_name == model_EnrollmentFlow.enrollment_success_template
mocked_analytics_module.returned_success.assert_called_once()


@pytest.mark.django_db
@pytest.mark.usefixtures("mocked_session_agency", "mocked_session_eligible")
def test_success_no_authentication(client, mocked_session_flow_does_not_use_claims_verification, mocked_analytics_module):
def test_success_no_authentication(client, mocked_session_flow_does_not_use_claims_verification):
path = reverse(routes.ENROLLMENT_SUCCESS)
response = client.get(path)

assert response.status_code == 200
assert (
response.template_name == mocked_session_flow_does_not_use_claims_verification.return_value.enrollment_success_template
)
mocked_analytics_module.returned_success.assert_called_once()

0 comments on commit ac1f54f

Please sign in to comment.