Repository: cal-itp/benefits

Issue:
Eligibility index does not reset eligibility types
## Steps to Reproduce
1. Once #344 is merged, follow the steps under **Testing** in #338 (copied here for convenience):

> * [x] Remove your local db and local compiled language files, then run `bin/init.sh`
>   * [x] Observe that the migrations run correctly, the fixture data is loaded, and the language files are compiled
> * [x] Open the app locally and select the agency configured above with multiple verifiers
>   * [x] Observe the `eligibility:index` view with different verifier selections
> * [x] Select one of the verifiers
>   * [x] Observe the verifier-specific `eligibility:start` view
>   * [x] Confirm verification of a test user
> * [x] Go back to `eligibility:index` and select the other verifier
>   * [x] Observe the verifier-specific `eligibility:start` view
>   * [x] Confirm verification of a test user

## Expected Result
For the last step, you should see a verifier-specific `eligibility:confirm` view / form and fill that out to then see the success page.

## Actual Result
You go straight from the second verifier's `eligibility:start` view to the success page due to your previous successful verification with the other verifier.


Discussion:
@angela-tran hmm, [`eligibility:index` does reset the eligibility types](https://github.com/cal-itp/benefits/blob/dev/benefits/eligibility/views.py#L20):

```python
@decorator_from_middleware(middleware.AgencySessionRequired)
def index(request):
    """View handler for the eligibility verifier selection form."""

    session.update(request, eligibility_types=[], origin=reverse("eligibility:index"))

    # ...
```

But looking closer at the [`session.update()` for the `eligibility_types` parameter](https://github.com/cal-itp/benefits/blob/dev/benefits/core/session.py#L203), I think that is the problem:

```python
if eligibility_types is not None and isinstance(eligibility_types, list):
    logger.debug(f"Update session {_ELIGIBILITY}")
    if len(eligibility_types) > 1:
        raise NotImplementedError("Multiple eligibilities are not supported at this time.")
    elif len(eligibility_types) == 1:
        # get the eligibility corresponding to the session's agency
        a = models.TransitAgency.by_id(request.session[_AGENCY])
        t = str(eligibility_types[0]).strip()
        request.session[_ELIGIBILITY] = a.get_type_id(t)
```

We aren't actually clearing the eligibility from session!

Resolving patch:
diff --git a/benefits/core/session.py b/benefits/core/session.py
--- a/benefits/core/session.py
+++ b/benefits/core/session.py
@@ -209,6 +209,9 @@ def update(request, agency=None, debug=None, eligibility_types=None, origin=None
             a = models.TransitAgency.by_id(request.session[_AGENCY])
             t = str(eligibility_types[0]).strip()
             request.session[_ELIGIBILITY] = a.get_type_id(t)
+        else:
+            # empty list, clear session eligibility
+            request.session[_ELIGIBILITY] = None
     if origin is not None:
         logger.debug(f"Update session {_ORIGIN}")
         request.session[_ORIGIN] = origin
diff --git a/benefits/eligibility/views.py b/benefits/eligibility/views.py
--- a/benefits/eligibility/views.py
+++ b/benefits/eligibility/views.py
@@ -58,6 +58,7 @@ def index(request):
 def start(request):
     """View handler for the eligibility verification getting started screen."""
 
+    session.update(request, eligibility_types=[])
     verifier = session.verifier(request)
 
     page = viewmodels.Page(


Test patch: