Skip to content

Commit

Permalink
test: success paths for enrollment with non-expiring flows
Browse files Browse the repository at this point in the history
  • Loading branch information
angela-tran committed Sep 4, 2024
1 parent 8a441f1 commit 80369e6
Showing 1 changed file with 80 additions and 0 deletions.
80 changes: 80 additions & 0 deletions tests/pytest/in_person/test_views.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,48 @@
from django.urls import reverse

import pytest
from littlepay.api.funding_sources import FundingSourceResponse
from littlepay.api.groups import GroupFundingSourceResponse

from benefits.routes import routes


@pytest.fixture
def card_tokenize_form_data():
return {"card_token": "tokenized_card"}


@pytest.fixture
def invalid_form_data():
return {"invalid": "data"}


@pytest.fixture
def mocked_funding_source():
return FundingSourceResponse(
id="0",
card_first_digits="0000",
card_last_digits="0000",
card_expiry_month="12",
card_expiry_year="2024",
card_scheme="visa",
form_factor="physical",
participant_id="cst",
is_fpan=False,
related_funding_sources=[],
)


@pytest.fixture
def mocked_group_funding_source_no_expiry(mocked_funding_source):
return GroupFundingSourceResponse(
id=mocked_funding_source.id,
created_date=None,
updated_date=None,
expiry_date=None,
)


@pytest.mark.django_db
@pytest.mark.parametrize("viewname", [routes.IN_PERSON_ELIGIBILITY, routes.IN_PERSON_ENROLLMENT])
def test_view_not_logged_in(client, viewname):
Expand Down Expand Up @@ -58,3 +91,50 @@ def test_enrollment_logged_in_post_invalid_form(admin_client, invalid_form_data)

with pytest.raises(Exception, match=r"form"):
admin_client.post(path, invalid_form_data)


@pytest.mark.django_db
@pytest.mark.usefixtures("mocked_session_agency", "mocked_session_flow")
def test_enrollment_logged_in_post_valid_form_success_does_not_support_expiration_no_expiry(
mocker,
admin_client,
card_tokenize_form_data,
model_EnrollmentFlow_does_not_support_expiration,
mocked_funding_source,
):
mock_client_cls = mocker.patch("benefits.enrollment.views.Client")
mock_client = mock_client_cls.return_value
mock_client.get_funding_source_by_token.return_value = mocked_funding_source

path = reverse(routes.IN_PERSON_ENROLLMENT)
response = admin_client.post(path, card_tokenize_form_data)

mock_client.link_concession_group_funding_source.assert_called_once_with(
funding_source_id=mocked_funding_source.id, group_id=model_EnrollmentFlow_does_not_support_expiration.group_id
)
assert response.status_code == 200
assert response.template_name == "in_person/enrollment/success.html"


@pytest.mark.django_db
@pytest.mark.usefixtures("mocked_session_agency", "mocked_session_flow")
def test_enrollment_logged_in_post_valid_form_success_does_not_support_expiration_customer_already_enrolled_no_expiry(
mocker,
admin_client,
card_tokenize_form_data,
mocked_funding_source,
mocked_group_funding_source_no_expiry,
):
mock_client_cls = mocker.patch("benefits.enrollment.views.Client")
mock_client = mock_client_cls.return_value
mock_client.get_funding_source_by_token.return_value = mocked_funding_source

mocker.patch("benefits.enrollment.views._get_group_funding_source", return_value=mocked_group_funding_source_no_expiry)

path = reverse(routes.IN_PERSON_ENROLLMENT)
response = admin_client.post(path, card_tokenize_form_data)

mock_client.link_concession_group_funding_source.assert_not_called()

assert response.status_code == 200
assert response.template_name == "in_person/enrollment/success.html"

0 comments on commit 80369e6

Please sign in to comment.