diff --git a/openedx/core/djangoapps/user_authn/api/tests/test_views.py b/openedx/core/djangoapps/user_authn/api/tests/test_views.py index 236c096bcb..1956834f1d 100644 --- a/openedx/core/djangoapps/user_authn/api/tests/test_views.py +++ b/openedx/core/djangoapps/user_authn/api/tests/test_views.py @@ -105,7 +105,9 @@ class MFEContextViewTest(ThirdPartyAuthTestMixin, APITestCase): 'countryCode': self.country_code }, 'registration_fields': {}, - 'optional_fields': {}, + 'optional_fields': { + 'extended_profile': [], + }, } @patch.dict(settings.FEATURES, {'ENABLE_THIRD_PARTY_AUTH': False}) @@ -319,6 +321,18 @@ class MFEContextViewTest(ThirdPartyAuthTestMixin, APITestCase): assert response.status_code == status.HTTP_200_OK assert list(response.data['registration_fields']['fields'].keys()) == ['specialty'] + @override_settings( + ENABLE_DYNAMIC_REGISTRATION_FIELDS=True, + ) + @patch.dict(settings.FEATURES, {'ENABLE_THIRD_PARTY_AUTH': False}) + def test_response_structure(self): + """ + Test that API return valid response dictionary with both required and optional fields + """ + response = self.client.get(self.url, self.query_params) + + assert response.data == self.get_context() + @skip_unless_lms class SendAccountActivationEmail(UserAPITestCase): diff --git a/openedx/core/djangoapps/user_authn/api/views.py b/openedx/core/djangoapps/user_authn/api/views.py index 1ca209afff..7e84a67473 100644 --- a/openedx/core/djangoapps/user_authn/api/views.py +++ b/openedx/core/djangoapps/user_authn/api/views.py @@ -55,22 +55,22 @@ class MFEContextView(APIView): context = { 'context_data': get_mfe_context(request, redirect_to, third_party_auth_hint), 'registration_fields': {}, - 'optional_fields': {}, + 'optional_fields': { + 'extended_profile': [] + }, } - if settings.ENABLE_DYNAMIC_REGISTRATION_FIELDS: - if is_register_page: - registration_fields = RegistrationFieldsContext().get_fields() - context['registration_fields'].update({ - 'fields': registration_fields, + if settings.ENABLE_DYNAMIC_REGISTRATION_FIELDS and is_register_page: + registration_fields = RegistrationFieldsContext().get_fields() + context['registration_fields'].update({ + 'fields': registration_fields, + }) + optional_fields = RegistrationFieldsContext('optional').get_fields() + if optional_fields: + context['optional_fields'].update({ + 'fields': optional_fields, 'extended_profile': configuration_helpers.get_value('extended_profile_fields', []), }) - optional_fields = RegistrationFieldsContext('optional').get_fields() - if optional_fields: - context['optional_fields'].update({ - 'fields': optional_fields, - 'extended_profile': configuration_helpers.get_value('extended_profile_fields', []), - }) return Response( status=status.HTTP_200_OK,