fix: get merged response from mfe_config and mfe_config_mymfe

This commit is contained in:
María Fernanda Magallanes Z
2022-06-09 08:53:48 -04:00
committed by Maria Fernanda Magallanes Zubillaga
parent 7f5eb296a3
commit 9069ce9950
2 changed files with 28 additions and 3 deletions

View File

@@ -32,6 +32,21 @@ class MFEConfigTestCase(ApiTestCase):
response_json = self.get_json(self.mfe_config_api_url)
assert response_json == mfe_config
def test_get_mfe_config_with_queryparams(self):
"""Test the get mfe config with a query params from site configuration.
Expected result:
- Inside self.get_json pass the response is a json and the status is 200 asserts.
- The configuration obtained by the api is equal to its site configuration in the
MFE_CONFIG and MFE_CONFIG_MYMFE merged on top.
"""
mfe_config = configuration_helpers.get_value('MFE_CONFIG', {})
mfe = "mymfe"
mfe_config.update(configuration_helpers.get_value(f'MFE_CONFIG_{mfe.upper()}', {}))
response_json = self.get_json(f'{self.mfe_config_api_url}?mfe={mfe}')
assert response_json == mfe_config
@patch.dict(settings.FEATURES, {'ENABLE_MFE_API': False})
def test_404_get_mfe_config(self):
"""Test the 404 not found response from get mfe config.

View File

@@ -21,11 +21,21 @@ class MFEConfigView(APIView):
def get(self, request):
"""
GET /api/mfe/v1/config
or
GET /api/mfe/v1/config?mfe=name_of_mfe
**GET Response Values**
```
{
"LOGO_URL": "https://example.com/logo.png",
"BASE_URL": "https://name_of_mfe.example.com",
"LANGUAGE_PREFERENCE_COOKIE_NAME": "example-language-preference",
"CREDENTIALS_BASE_URL": "https://credentials.example.com",
"DOSCOVERY_API_BASE_URL": "https://discovery.example.com",
"LMS_BASE_URL": "https://courses.example.com",
"LOGIN_URL": "https://courses.example.com/login",
"LOGOUT_URL": "https://courses.example.com/logout",
"STUDIO_BASE_URL": "https://studio.example.com",
"LOGO_URL": "https://courses.example.com/logo.png"
}
```
"""
@@ -34,9 +44,9 @@ class MFEConfigView(APIView):
msg = 'MFE API not found. Try setting FEATURES["ENABLE_MFE_API"] to true.'
return JsonResponse({'message': msg}, status=status.HTTP_404_NOT_FOUND)
mfe_config = {'MFE_CONFIG': configuration_helpers.get_value('MFE_CONFIG', {})}
mfe_config = configuration_helpers.get_value('MFE_CONFIG', {})
if request.query_params.get('mfe'):
mfe = str(request.query_params.get('mfe')).upper()
mfe_config[f'MFE_CONFIG_{mfe}']= configuration_helpers.get_value(f'MFE_CONFIG_{mfe}',{})
mfe_config.update(configuration_helpers.get_value(f'MFE_CONFIG_{mfe}', {}))
return JsonResponse(mfe_config, status=status.HTTP_200_OK)