Skip to content

Commit

Permalink
Navigating to org details from unrelated paths now redirects the user…
Browse files Browse the repository at this point in the history
… back to the contact page (#1654)

* Navigating to org details from unrelated paths now redirects the user back to the contact page

* Fix 500 error when navigating to /contact/organization-details

* Re-arrange some route validation logic

* fix test

* Formatting

* Fix issue navigating to org details after selecting a non-demo support_type

* formatting

* Revert unintended commit of files

* Restore edited devcontainer.json
  • Loading branch information
whabanks authored Sep 5, 2023
1 parent 79aeda1 commit 624d267
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 17 deletions.
8 changes: 6 additions & 2 deletions app/main/views/contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,14 @@ def _validate_fields_present(current_step: str, form_data: dict) -> bool:
base_requirement = {"name", "support_type", "email_address"}
primary_purpose_requirement = base_requirement.union({"department_org_name", "program_service_name", "intended_recipients"})

if current_step in ["message", "demo.org_details"]:
if not form_data or SESSION_FORM_KEY not in session:
return False
if current_step == "message":
return base_requirement.issubset(form_data)
elif current_step == "demo.org_details":
return base_requirement.issubset(form_data) and form_data.get("support_type") == "demo"
elif current_step == "demo.primary_purpose":
return set(form_data).issuperset(primary_purpose_requirement)
return set(form_data).issuperset(primary_purpose_requirement) and form_data.get("support_type") == "demo"

return False

Expand Down
51 changes: 36 additions & 15 deletions tests/app/main/test_contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,29 +92,50 @@ def test_back_link_goes_to_previous_step(client_request):
@pytest.mark.parametrize(
"view, expected_view, request_data",
[
(".demo_organization_details", ".contact", [{}]),
(".demo_organization_details", ".contact", {}),
(
".demo_organization_details",
".contact",
{
"name": "John",
"email_address": "[email protected]",
"support_type": "Bad_support_type",
},
),
(
".demo_organization_details",
".contact",
{
"name": "John",
"email_address": "[email protected]",
"support_type": "other",
},
),
(
".demo_organization_details",
".contact",
{
"name": "John",
"email_address": "[email protected]",
"support_type": "ask_question",
},
),
(
".demo_primary_purpose",
".contact",
[
{
"name": "John",
"email_address": "[email protected]",
"support_type": "demo",
},
{},
],
{
"name": "John",
"email_address": "[email protected]",
"support_type": "demo",
},
),
(".message", ".contact", [{}]),
(".message", ".contact", {}),
],
)
def test_nav_to_invalid_step_redirects_to_contact(client_request, view, expected_view, request_data):
with client_request.session_transaction() as session:
for data in request_data:
session["contact_form"] = data
client_request.get_url(
url_for(view), _expected_status=302, _test_page_title=False, _expected_redirect=url_for(".contact")
)
session["contact_form"] = request_data
client_request.get_url(url_for(view), _expected_status=302, _test_page_title=False, _expected_redirect=url_for(".contact"))


@pytest.mark.parametrize("support_type", ["ask_question", "technical_support", "give_feedback", "other"])
Expand Down

0 comments on commit 624d267

Please sign in to comment.