Repository: cal-itp/benefits

Issue:
Update Enrollment Success page with sign out button / text


<img width="648" alt="image" src="https://user-images.githubusercontent.com/3673236/165405417-9db954d7-727a-42a1-a553-e76bea14a8e5.png">



Discussion:

Resolving patch:
diff --git a/benefits/core/viewmodels.py b/benefits/core/viewmodels.py
--- a/benefits/core/viewmodels.py
+++ b/benefits/core/viewmodels.py
@@ -2,6 +2,7 @@
 The core application: view model definitions for the root of the webapp.
 """
 from django.utils.translation import pgettext, gettext as _
+from django.urls import reverse
 
 from benefits.core import models
 
@@ -81,6 +82,12 @@ def login(**kwargs):
         btn = Button.primary(fallback_text="Login.gov", id="login", **kwargs)
         return btn
 
+    @staticmethod
+    def logout(**kwargs):
+        """Create a button that logs user out, with a login.gov button, with a login.gov logo and fallback text"""
+        btn = Button.primary(fallback_text="Login.gov", id="login", url=reverse("oauth:logout"), text="", **kwargs)
+        return btn
+
 
 class Icon:
     """Represents an icon."""
diff --git a/benefits/enrollment/views.py b/benefits/enrollment/views.py
--- a/benefits/enrollment/views.py
+++ b/benefits/enrollment/views.py
@@ -3,6 +3,7 @@
 """
 import logging
 
+from django.conf import settings
 from django.http import JsonResponse
 from django.template.response import TemplateResponse
 from django.urls import reverse
@@ -10,7 +11,7 @@
 from django.utils.translation import pgettext, gettext as _
 
 from benefits.core import models, session, viewmodels
-from benefits.core.middleware import EligibleSessionRequired, pageview_decorator
+from benefits.core.middleware import EligibleSessionRequired, VerifierSessionRequired, pageview_decorator
 from benefits.core.views import PageTemplateResponse
 from . import api, forms
 
@@ -143,17 +144,38 @@ def retry(request):
 
 
 @pageview_decorator
+@decorator_from_middleware(VerifierSessionRequired)
 def success(request):
     """View handler for the final success page."""
     request.path = "/enrollment/success"
     session.update(request, origin=reverse("enrollment:success"))
+    verifier = session.verifier(request)
 
-    page = viewmodels.Page(
-        title=_("enrollment.pages.success.title"),
-        icon=viewmodels.Icon("bankcardcheck", pgettext("image alt text", "core.icons.bankcardcheck")),
-        content_title=_("enrollment.pages.success.title"),
-        classes="without-warning",
-    )
+    if verifier.requires_authentication:
+        if settings.OAUTH_CLIENT_NAME is None:
+            raise Exception("EligibilityVerifier requires authentication, but OAUTH_CLIENT_NAME is None")
+
+        if session.logged_in(request):
+            button = viewmodels.Button.logout()
+            page = viewmodels.Page(
+                title=_("enrollment.pages.success.title"),
+                icon=viewmodels.Icon("bankcardcheck", pgettext("image alt text", "core.icons.bankcardcheck")),
+                content_title=_("enrollment.pages.success.title"),
+                button=button,
+                classes="logged-in",
+            )
+        else:
+            page = viewmodels.Page(
+                title=_("enrollment.pages.success.title"),
+                content_title=_("enrollment.pages.success.logout.title"),
+                classes="logged-out",
+            )
+    else:
+        page = viewmodels.Page(
+            title=_("enrollment.pages.success.title"),
+            icon=viewmodels.Icon("bankcardcheck", pgettext("image alt text", "core.icons.bankcardcheck")),
+            content_title=_("enrollment.pages.success.title"),
+        )
 
     help_link = reverse("core:help")
     context_dict = {**page.context_dict(), **{"help_link": help_link}}


Test patch:
diff --git a/tests/cypress/specs/ui/enrollment.spec.js b/tests/cypress/specs/ui/enrollment.spec.js
--- a/tests/cypress/specs/ui/enrollment.spec.js
+++ b/tests/cypress/specs/ui/enrollment.spec.js
@@ -7,7 +7,8 @@ describe("Single Verifier, No AuthProvider: Enrollment success page", () => {
     cy.contains(agencies[1].fields.short_name).click();
     cy.contains("Get started").click();
     cy.contains("Continue").click();
-    cy.visit("/enrollment/success");
+    // https://github.com/cypress-io/cypress/issues/18690
+    cy.window().then((win) => (win.location.href = "/enrollment/success"));
   });
 
   it("Has the appropriate English copy for all flows", () => {
@@ -23,30 +24,3 @@ describe("Single Verifier, No AuthProvider: Enrollment success page", () => {
     cy.contains("No te cobraron nada hoy.");
   });
 });
-
-describe("Multiple Verifier, with AuthProvider: Enrollment success page", () => {
-  beforeEach(() => {
-    cy.visit("/");
-    // Selecting ABC will go down the multiple verifier flow
-    cy.contains(agencies[0].fields.short_name).click();
-    cy.contains("Get started").click();
-    // Selecting Senior Discount will go down the auth provider flow
-    cy.get("input:radio").first().click();
-    cy.contains("Continue").click();
-    cy.contains("Create an account or sign in with");
-    cy.visit("/enrollment/success");
-  });
-
-  it("Has the appropriate English copy for all flows and Login.gov instructions", () => {
-    cy.contains("Success! Your discount is now linked to your bank card.");
-    cy.contains("You were not charged anything today.");
-  });
-
-  it("Has the appropriate Spanish copy for all flows and Login.gov instructions", () => {
-    cy.contains("Español").click();
-    cy.contains(
-      "Felicidades! Su descuento ahora está vinculado a su tarjeta bancaria."
-    );
-    cy.contains("No te cobraron nada hoy.");
-  });
-});