diff --git a/openedx/core/djangoapps/user_authn/api/tests/test_serializers.py b/openedx/core/djangoapps/user_authn/api/tests/test_serializers.py index 77d0dbb27153..c356b6a9b0c1 100644 --- a/openedx/core/djangoapps/user_authn/api/tests/test_serializers.py +++ b/openedx/core/djangoapps/user_authn/api/tests/test_serializers.py @@ -10,7 +10,7 @@ SERIALIZED_MFE_CONTEXT_WITH_TPA_DATA, SERIALIZED_MFE_CONTEXT_WITHOUT_TPA_DATA, ) -from openedx.core.djangoapps.user_authn.serializers import MFEContextSerializer +from openedx.core.djangoapps.user_authn.serializers import ContextDataSerializer, MFEContextSerializer class TestMFEContextSerializer(TestCase): @@ -44,3 +44,82 @@ def test_mfe_context_serializer_default_response(self): serialized_data, SERIALIZED_MFE_CONTEXT_WITHOUT_TPA_DATA ) + + def test_context_data_serializer_includes_enterprise_branding_when_present(self): + context_data = { + 'currentProvider': None, + 'platformName': 'Open edX', + 'providers': [], + 'secondaryProviders': [], + 'finishAuthUrl': None, + 'errorMessage': None, + 'registerFormSubmitButtonText': None, + 'autoSubmitRegForm': False, + 'syncLearnerProfileData': False, + 'countryCode': None, + 'welcomePageRedirectUrl': None, + 'pipeline_user_details': { + 'username': 'jdoe', + 'email': 'jdoe@example.com', + 'fullname': 'Jane Doe', + 'first_name': 'Jane', + 'last_name': 'Doe', + }, + 'enterpriseBranding': { + 'enterpriseName': 'Example Enterprise', + 'enterpriseLogoUrl': 'https://example.com/logo.png', + 'enterpriseBrandedWelcomeString': 'Welcome, Enterprise Learner', + 'enterpriseSlug': 'example-enterprise', + 'platformWelcomeString': 'Welcome to the Platform', + }, + } + + serialized = ContextDataSerializer(context_data).data + + self.assertDictEqual( + serialized['enterpriseBranding'], + { + 'enterpriseName': 'Example Enterprise', + 'enterpriseLogoUrl': 'https://example.com/logo.png', + 'enterpriseBrandedWelcomeString': 'Welcome, Enterprise Learner', + 'enterpriseSlug': 'example-enterprise', + 'platformWelcomeString': 'Welcome to the Platform', + } + ) + + self.assertDictEqual( + serialized['pipelineUserDetails'], + { + 'username': 'jdoe', + 'email': 'jdoe@example.com', + 'name': 'Jane Doe', + 'firstName': 'Jane', + 'lastName': 'Doe', + } + ) + + def test_context_data_serializer_omits_enterprise_branding_when_absent(self): + context_data = { + 'currentProvider': None, + 'platformName': 'Open edX', + 'providers': [], + 'secondaryProviders': [], + 'finishAuthUrl': None, + 'errorMessage': None, + 'registerFormSubmitButtonText': None, + 'autoSubmitRegForm': False, + 'syncLearnerProfileData': False, + 'countryCode': None, + 'welcomePageRedirectUrl': None, + 'pipeline_user_details': { + 'username': 'jdoe', + 'email': 'jdoe@example.com', + 'fullname': 'Jane Doe', + 'first_name': 'Jane', + 'last_name': 'Doe', + }, + } + + serialized = ContextDataSerializer(context_data).data + + self.assertNotIn('enterpriseBranding', serialized) diff --git a/openedx/core/djangoapps/user_authn/serializers.py b/openedx/core/djangoapps/user_authn/serializers.py index ac41d263e91d..b35a0aac4b74 100644 --- a/openedx/core/djangoapps/user_authn/serializers.py +++ b/openedx/core/djangoapps/user_authn/serializers.py @@ -65,6 +65,10 @@ class ContextDataSerializer(serializers.Serializer): countryCode = serializers.CharField(allow_null=True) welcomePageRedirectUrl = serializers.CharField(allow_null=True) pipelineUserDetails = serializers.SerializerMethodField() + enterpriseBranding = EnterpriseBrandingSerializer( + allow_null=True, + required=False, + ) def get_pipelineUserDetails(self, obj): if obj.get('pipeline_user_details'):