Repository: cal-itp/benefits

Issue:
Show logged out users Enrollment success message
Another on the heels of #997

1. Navigate to dev
2. Choose senior, log in
3. Before connecting card, log out
4. Connect card
5. See below screen

![image](https://user-images.githubusercontent.com/1783439/193970399-c56d3bcd-c121-41a0-ac87-126d30b5f123.png)

## Expected behavior

The user should see the "Success" message / context. Only if they logout from here, should they see the above "You have logged out" message.

## Additional context

Addressing the missing icon in #1010



Discussion:

Resolving patch:
diff --git a/benefits/core/urls.py b/benefits/core/urls.py
--- a/benefits/core/urls.py
+++ b/benefits/core/urls.py
@@ -48,4 +48,5 @@ def to_url(self, agency):
     path("help", views.help, name="help"),
     path("<agency:agency>", views.agency_index, name="agency_index"),
     path("<agency:agency>/publickey", views.agency_public_key, name="agency_public_key"),
+    path("logged_out", views.logged_out, name="logged_out"),
 ]
diff --git a/benefits/core/views.py b/benefits/core/views.py
--- a/benefits/core/views.py
+++ b/benefits/core/views.py
@@ -6,7 +6,7 @@
 from django.template import loader
 from django.template.response import TemplateResponse
 from django.urls import reverse
-from django.utils.translation import gettext as _
+from django.utils.translation import pgettext, gettext as _
 
 from . import models, session, viewmodels
 from .middleware import pageview_decorator
@@ -14,6 +14,7 @@
 ROUTE_INDEX = "core:index"
 ROUTE_ELIGIBILITY = "eligibility:index"
 ROUTE_HELP = "core:help"
+ROUTE_LOGGED_OUT = "core:logged_out"
 
 TEMPLATE_PAGE = "core/page.html"
 TEMPLATE_AGENCY = "core/agency_index.html"
@@ -151,3 +152,14 @@ def server_error(request, template_name="500.html"):
     t = loader.get_template(template_name)
 
     return HttpResponseServerError(t.render(page.context_dict()))
+
+
+def logged_out(request):
+    """View handler for the final log out confirmation message."""
+    page = viewmodels.Page(
+        title=_("core.pages.logged_out.title"),
+        headline=_("core.pages.logged_out.headline"),
+        icon=viewmodels.Icon("happybus", pgettext("image alt text", "core.icons.happybus")),
+    )
+
+    return TemplateResponse(request, TEMPLATE_PAGE, page.context_dict())
diff --git a/benefits/enrollment/views.py b/benefits/enrollment/views.py
--- a/benefits/enrollment/views.py
+++ b/benefits/enrollment/views.py
@@ -12,7 +12,7 @@
 
 from benefits.core import models, session, viewmodels
 from benefits.core.middleware import EligibleSessionRequired, VerifierSessionRequired, pageview_decorator
-from benefits.core.views import ROUTE_HELP
+from benefits.core.views import ROUTE_HELP, ROUTE_LOGGED_OUT
 from . import analytics, api, forms
 
 
@@ -168,15 +168,11 @@ def success(request):
 
     page = viewmodels.Page(title=_("enrollment.pages.success.title"), headline=_("enrollment.pages.success.headline"))
 
-    if verifier.is_auth_required:
-        if session.logged_in(request):
-            page.buttons = [viewmodels.Button.logout()]
-            page.classes = ["logged-in"]
-        else:
-            page.classes = ["logged-out"]
-            page.headline = _("enrollment.pages.success.logged_out.headline")
-            page.icon = (viewmodels.Icon("happybus", pgettext("image alt text", "core.icons.happybus")),)
-            return TemplateResponse(request, TEMPLATE_SUCCESS, page.context_dict())
+    if verifier.is_auth_required and session.logged_in(request):
+        # overwrite origin for a logged in user
+        # if they click the logout button, they are taken to the new route
+        session.update(request, origin=reverse(ROUTE_LOGGED_OUT))
+        page.buttons = [viewmodels.Button.logout()]
 
     success_item = viewmodels.MediaItem(
         icon=viewmodels.Icon("happybus", pgettext("image alt text", "core.icons.happybus")),


Test patch:
diff --git a/tests/pytest/core/test_views.py b/tests/pytest/core/test_views.py
--- a/tests/pytest/core/test_views.py
+++ b/tests/pytest/core/test_views.py
@@ -4,7 +4,7 @@
 
 from benefits.core.models import EligibilityVerifier, TransitAgency
 import benefits.core.session
-from benefits.core.views import ROUTE_INDEX, ROUTE_HELP, TEMPLATE_AGENCY, bad_request, csrf_failure
+from benefits.core.views import ROUTE_INDEX, ROUTE_HELP, ROUTE_LOGGED_OUT, TEMPLATE_AGENCY, bad_request, csrf_failure
 
 
 ROUTE_AGENCY = "core:agency_index"
@@ -170,3 +170,13 @@ def test_not_found_no_active_agency(mocker, client, mocked_session_update):
     assert response.status_code == 404
     assert "origin" in mocked_session_update.call_args.kwargs
     assert mocked_session_update.call_args.kwargs["origin"] == reverse(ROUTE_INDEX)
+
+
+@pytest.mark.django_db
+def test_logged_out(client):
+    path = reverse(ROUTE_LOGGED_OUT)
+    response = client.get(path)
+
+    assert response.status_code == 200
+    assert "happybus" in str(response.content)
+    assert "logged out" in str(response.content)
diff --git a/tests/pytest/enrollment/test_views.py b/tests/pytest/enrollment/test_views.py
--- a/tests/pytest/enrollment/test_views.py
+++ b/tests/pytest/enrollment/test_views.py
@@ -5,6 +5,7 @@
 import pytest
 
 from benefits.core.middleware import TEMPLATE_USER_ERROR
+from benefits.core.views import ROUTE_LOGGED_OUT
 from benefits.enrollment.views import (
     ROUTE_INDEX,
     ROUTE_TOKEN,
@@ -206,7 +207,7 @@ def test_success_authentication_logged_in(mocker, client):
     assert response.status_code == 200
     assert response.template_name == TEMPLATE_SUCCESS
     assert "page" in response.context_data
-    assert "logged-in" in response.context_data["page"].classes
+    assert {"origin": reverse(ROUTE_LOGGED_OUT)} in mock_session.update.call_args
 
 
 @pytest.mark.django_db
@@ -221,7 +222,6 @@ def test_success_authentication_not_logged_in(mocker, client):
     assert response.status_code == 200
     assert response.template_name == TEMPLATE_SUCCESS
     assert "page" in response.context_data
-    assert "logged-out" in response.context_data["page"].classes
 
 
 @pytest.mark.django_db
@@ -233,4 +233,3 @@ def test_success_no_authentication(client):
     assert response.status_code == 200
     assert response.template_name == TEMPLATE_SUCCESS
     assert "page" in response.context_data
-    assert "logged-in" not in response.context_data["page"].classes