diff --git a/app/commands.py b/app/commands.py index 69d3b23ec..e4fdc7cb5 100644 --- a/app/commands.py +++ b/app/commands.py @@ -752,12 +752,13 @@ def create_admin_jwt(): @notify_command(name="create-user-jwt") @click.option("-t", "--token", required=True, prompt=False) def create_user_jwt(token): - if getenv("NOTIFY_ENVIRONMENT", "") != "development": + if getenv("NOTIFY_ENVIRONMENT", "") not in ["development", "test"]: current_app.logger.error("Can only be run in development") return service_id = token[-73:-37] api_key = token[-36:] - current_app.logger.info(create_jwt_token(api_key, service_id)) + token = create_jwt_token(api_key, service_id) + current_app.logger.info(token) def _update_template(id, name, template_type, content, subject): diff --git a/tests/app/test_commands.py b/tests/app/test_commands.py index 3644458bc..98f163d89 100644 --- a/tests/app/test_commands.py +++ b/tests/app/test_commands.py @@ -13,6 +13,7 @@ from app.commands import ( bulk_invite_user_to_service, create_new_service, create_test_user, + create_user_jwt, download_csv_file_by_name, dump_sms_senders, dump_user_info, @@ -761,3 +762,12 @@ def test_get_service_sender_phones(mock_execute, notify_api): result = runner.invoke(get_service_sender_phones, ["-s", "service-id"]) assert result.exit_code == 0 mock_execute.assert_called_once() + + +@patch("app.commands.current_app.logger.info") +def test_create_user_jwt(mock_logger, notify_api, sample_api_key, sample_service): + token = f"{sample_service.id}{sample_api_key}" + runner = notify_api.test_cli_runner() + result = runner.invoke(create_user_jwt, ["-t", token]) + assert result.exit_code == 0 + mock_logger.assert_called_once()