Only show ‘Choose service’ if multiple services

When the user clicks ‘GOV.UK Notify’ in the header, they should, by
default, be redirected to the dashboard for their service. They should
only see the ‘Choose service’ page if they have multiple services.

This also allows some logic to be factored out of the template, so one
route now handles all this redirection.

In the future we might want to keep the last-used service in the
session, and always redirect to that. But for now, this should fix most
of the confusion for first-time users.
This commit is contained in:
Chris Hill-Scott
2016-03-29 10:39:01 +01:00
parent 8a55e61dac
commit eb279c88d4
3 changed files with 61 additions and 9 deletions

View File

@@ -23,6 +23,47 @@ def test_should_show_choose_services_page(app_,
assert 'List all services' not in resp_data
def test_redirect_if_only_one_service(
app_,
mock_login,
mock_get_user,
api_user_active,
mock_get_services_with_one_service
):
with app_.test_request_context():
with app_.test_client() as client:
client.login(api_user_active)
response = client.get(url_for('main.show_all_services_or_dashboard'))
service = mock_get_services_with_one_service.side_effect()['data'][0]
assert response.status_code == 302
assert response.location == url_for('main.service_dashboard', service_id=service['id'], _external=True)
def test_redirect_if_multiple_services(
app_,
mock_login,
mock_get_user,
api_user_active,
mock_get_services
):
with app_.test_request_context():
with app_.test_client() as client:
client.login(api_user_active)
response = client.get(url_for('main.show_all_services_or_dashboard'))
assert response.status_code == 302
assert response.location == url_for('main.choose_service', _external=True)
def test_should_redirect_if_not_logged_in(app_):
with app_.test_request_context():
with app_.test_client() as client:
response = client.get(url_for('main.show_all_services_or_dashboard'))
assert response.status_code == 302
assert response.location == url_for('main.index', _external=True)
def test_should_show_all_services_for_platform_admin_user(app_,
platform_admin_user,
mock_get_services,