From a2d1dfe1f40f4c6692169d232dd9ac32f4a98355 Mon Sep 17 00:00:00 2001 From: Angela Tran Date: Wed, 27 Mar 2024 17:56:04 +0000 Subject: [PATCH] feat(enrollment): outline new scenarios that consider expiration --- benefits/enrollment/views.py | 55 ++++++++++++++++++++++++++++++------ 1 file changed, 47 insertions(+), 8 deletions(-) diff --git a/benefits/enrollment/views.py b/benefits/enrollment/views.py index 40301fb46a..52c5346eeb 100644 --- a/benefits/enrollment/views.py +++ b/benefits/enrollment/views.py @@ -92,14 +92,43 @@ def index(request): ) already_enrolled = group_funding_source is not None - - if not already_enrolled: - # enroll user with no expiration date, return success - client.link_concession_group_funding_source(group_id=group_id, funding_source_id=funding_source.id) - return _success(request, group_id) - else: - # no action, return success - return _success(request, group_id) + has_no_expiration_date = already_enrolled and group_funding_source.concession_expiry is None + has_expiration_date = already_enrolled and group_funding_source.concession_expiry is not None + + if has_expiration_date: + # set expiry on session + session.update(enrollment_expiry=group_funding_source.concession_expiry) + + if eligibility.supports_expiration: + if not already_enrolled: + # enroll user with an expiration date, return success + pass + else: + if has_no_expiration_date: + # update expiration of existing enrollment, return success + pass + else: + is_expired = _is_expired(group_funding_source.concession_expiry, eligibility.expiration_days) + is_within_reenrollment_window = _is_within_reenrollment_window(session.enrollment_reenrollment()) + + if is_expired or is_within_reenrollment_window: + # update expiration of existing enrollment, return success + pass + else: + # re-enrollment error, return enrollment error with expiration and reenrollment_date + pass + else: # eligibility does not support expiration + if not already_enrolled: + # enroll user with no expiration date, return success + client.link_concession_group_funding_source(group_id=group_id, funding_source_id=funding_source.id) + return _success(request, group_id) + else: + if has_no_expiration_date: + # no action, return success + return _success(request, group_id) + else: + # remove expiration date, return success + pass except HTTPError as e: analytics.returned_error(request, str(e)) @@ -145,6 +174,16 @@ def _get_group_funding_source(client: Client, group_id, funding_source_id): return matching_group_funding_source +def _is_expired(concession_expiry, expiration_days): + """Returns whether the passed in datetime is expired or not.""" + pass + + +def _is_within_reenrollment_window(concession_expiry, enrollment_reenrollment_date): + """Returns whether the passed in datetime is within the reenrollment window.""" + pass + + @decorator_from_middleware(EligibleSessionRequired) def retry(request): """View handler for a recoverable failure condition."""