mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-02-05 10:53:28 -05:00
Skip ‘choose service’ page if user has one service
We used to do this by redirecting on the choose service page. However when we
lost the dropdown and this page also became the page for adding a new service
(in 3617f2e936) the redirect was removed.
This commit re-adds the redirect on the two factor page, so that it only happens
on first login.
So the flows are:
**Multiple services**
```
`Sign in` → `Enter two factor code` → `Choose service` → `Service dashboard`
```
**One service**
```
`Sign in` → `Enter two factor code` → `Service dashboard`
```
**No services (you’ve deleted all your services)**
`Sign in` → `Enter two factor code` → `Choose service` → `Add new service`
This commit is contained in:
@@ -19,11 +19,35 @@ def test_should_render_two_factor_page(app_,
|
||||
assert '''We've sent you a text message with a verification code.''' in response.get_data(as_text=True)
|
||||
|
||||
|
||||
def test_should_login_user_and_redirect_to_dashboard(app_,
|
||||
api_user_active,
|
||||
mock_get_user,
|
||||
mock_get_user_by_email,
|
||||
mock_check_verify_code):
|
||||
def test_should_login_user_and_redirect_to_service_dashboard(app_,
|
||||
api_user_active,
|
||||
mock_get_user,
|
||||
mock_get_user_by_email,
|
||||
mock_check_verify_code,
|
||||
mock_get_services_with_one_service):
|
||||
with app_.test_request_context():
|
||||
with app_.test_client() as client:
|
||||
with client.session_transaction() as session:
|
||||
session['user_details'] = {
|
||||
'id': api_user_active.id,
|
||||
'email': api_user_active.email_address}
|
||||
response = client.post(url_for('main.two_factor'),
|
||||
data={'sms_code': '12345'})
|
||||
|
||||
assert response.status_code == 302
|
||||
assert response.location == url_for(
|
||||
'main.service_dashboard',
|
||||
service_id="596364a0-858e-42c8-9062-a8fe822260eb",
|
||||
_external=True
|
||||
)
|
||||
|
||||
|
||||
def test_should_login_user_and_redirect_to_choose_services(app_,
|
||||
api_user_active,
|
||||
mock_get_user,
|
||||
mock_get_user_by_email,
|
||||
mock_check_verify_code,
|
||||
mock_get_services):
|
||||
with app_.test_request_context():
|
||||
with app_.test_client() as client:
|
||||
with client.session_transaction() as session:
|
||||
@@ -57,7 +81,8 @@ def test_should_login_user_when_multiple_valid_codes_exist(app_,
|
||||
api_user_active,
|
||||
mock_get_user,
|
||||
mock_get_user_by_email,
|
||||
mock_check_verify_code):
|
||||
mock_check_verify_code,
|
||||
mock_get_services_with_one_service):
|
||||
with app_.test_request_context():
|
||||
with app_.test_client() as client:
|
||||
with client.session_transaction() as session:
|
||||
|
||||
@@ -92,15 +92,30 @@ def mock_get_services(mocker, user=None):
|
||||
def _create(user_id=None):
|
||||
import uuid
|
||||
service_one = service_json(
|
||||
uuid.uuid4(), "service_one", [user.id], 1000, True, False)
|
||||
"596364a0-858e-42c8-9062-a8fe822260eb", "service_one", [user.id], 1000, True, False)
|
||||
service_two = service_json(
|
||||
uuid.uuid4(), "service_two", [user.id], 1000, True, False)
|
||||
"147ad62a-2951-4fa1-9ca0-093cd1a52c52", "service_two", [user.id], 1000, True, False)
|
||||
return {'data': [service_one, service_two]}
|
||||
|
||||
return mocker.patch(
|
||||
'app.notifications_api_client.get_services', side_effect=_create)
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def mock_get_services_with_one_service(mocker, user=None):
|
||||
if user is None:
|
||||
user = api_user_active()
|
||||
|
||||
def _create(user_id=None):
|
||||
import uuid
|
||||
return {'data': [service_json(
|
||||
"596364a0-858e-42c8-9062-a8fe822260eb", "service_one", [user.id], 1000, True, False
|
||||
)]}
|
||||
|
||||
return mocker.patch(
|
||||
'app.notifications_api_client.get_services', side_effect=_create)
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def mock_delete_service(mocker, mock_get_service):
|
||||
def _delete(service_id):
|
||||
|
||||
Reference in New Issue
Block a user