Repository: openfun/richie

Issue:
Course glimpse from course search page miss new element for empty cover
## Bug Report

**Expected behavior/code**
With last commit from PR #637, course glimpse have a new element `<div class="course-glimpse__media__empty">{% trans "Cover" %}</div>` instead of `<img>` when course does not have a cover image. It should be available course glimpse without a cover.

**Actual Behavior**
Course search page from react frontend does not include this new element yet.

**Steps to Reproduce**
1. Test the PR #637 or wait for it to be merged in master
2. Create a empty new course or edit one to remove its cover image;
3. Make sure this course is added to the "Popular courses" section from homepage;
4. Go to homepage, course without cover display an grey square with "Cover" word;
5. Go to /courses/, the same course without cover does not display grey square;

**Environment**
- Richie version:
- Platform:

**Possible Solution**
<!--- Only if you have suggestions on a fix for the bug -->

**Additional context/Screenshots**
Add any other context about the problem here. If applicable, add screenshots to help explain.



Discussion:
I think the scope of this issue should be to harmonize the glimpse shown on the search page with the glimpse shown elsewhere in the CMS.

Resolving patch:
diff --git a/src/richie/apps/search/indexers/courses.py b/src/richie/apps/search/indexers/courses.py
--- a/src/richie/apps/search/indexers/courses.py
+++ b/src/richie/apps/search/indexers/courses.py
@@ -66,6 +66,7 @@ class CoursesIndexer:
         "categories",
         "cover_image",
         "organizations",
+        "organizations_names",
         "title.*",
     ]
     form = CourseSearchForm
@@ -512,6 +513,9 @@ def format_es_object_for_api(es_course, language=None):
             "absolute_url": get_best_field_language(source["absolute_url"], language),
             "categories": source["categories"],
             "cover_image": get_best_field_language(source["cover_image"], language),
+            "organization_highlighted": get_best_field_language(
+                source["organizations_names"], language
+            )[0],
             "organizations": source["organizations"],
             "state": CourseState(**state),
             "title": get_best_field_language(source["title"], language),


Test patch:
diff --git a/tests/apps/search/test_indexers_courses.py b/tests/apps/search/test_indexers_courses.py
--- a/tests/apps/search/test_indexers_courses.py
+++ b/tests/apps/search/test_indexers_courses.py
@@ -325,9 +325,10 @@ def test_indexers_courses_format_es_object_for_api(self):
             "_id": 93,
             "_source": {
                 "absolute_url": {"en": "campo-qui-format-do"},
+                "categories": [43, 86],
                 "cover_image": {"en": "image.jpg"},
                 "organizations": [42, 84],
-                "categories": [43, 86],
+                "organizations_names": {"en": ["Org 42", "Org 84"]},
                 "title": {"en": "Duis eu arcu erat"},
             },
             "fields": {
@@ -341,9 +342,10 @@ def test_indexers_courses_format_es_object_for_api(self):
             {
                 "id": 93,
                 "absolute_url": "campo-qui-format-do",
+                "categories": [43, 86],
                 "cover_image": "image.jpg",
+                "organization_highlighted": "Org 42",
                 "organizations": [42, 84],
-                "categories": [43, 86],
                 "title": "Duis eu arcu erat",
                 "state": CourseState(
                     0, datetime(2019, 3, 17, 21, 25, 52, 179667, pytz.utc)
diff --git a/tests/apps/search/test_query_courses.py b/tests/apps/search/test_query_courses.py
--- a/tests/apps/search/test_query_courses.py
+++ b/tests/apps/search/test_query_courses.py
@@ -31,6 +31,7 @@
         },
         "is_new": True,
         "organizations": ["P-00030001", "P-00030004", "L-000300010001"],
+        "organizations_names": {"en": ["Org 31", "Org 34", "Org 311"]},
         "title": {"en": "Artificial intelligence for mushroom picking"},
     },
     {
@@ -46,6 +47,7 @@
         },
         "is_new": True,
         "organizations": ["P-00030001", "P-00030003", "L-000300010002"],
+        "organizations_names": {"en": ["Org 31", "Org 33", "Org 312"]},
         "title": {"en": "Click-farms: managing the autumn harvest"},
     },
     {
@@ -61,6 +63,7 @@
         },
         "is_new": False,
         "organizations": ["P-00030002", "P-00030003", "L-000300020001"],
+        "organizations_names": {"en": ["Org 32", "Org 33", "Org 321"]},
         "title": {"en": "Building a data lake out of mountain springs"},
     },
     {
@@ -75,6 +78,7 @@
         },
         "is_new": False,
         "organizations": ["P-00030002", "P-00030004", "L-000300020002"],
+        "organizations_names": {"en": ["Org 32", "Org 34", "Org 322"]},
         "title": {"en": "Kung-fu moves for cloud infrastructure security"},
     },
 ]
@@ -323,6 +327,7 @@ def test_query_courses_match_all(self, *_):
                             "L-00020001",
                         ],
                         "cover_image": "image",
+                        "organization_highlighted": "Org 31",
                         "organizations": ["P-00030001", "P-00030004", "L-000300010001"],
                         "state": {
                             "priority": 0,
@@ -344,6 +349,7 @@ def test_query_courses_match_all(self, *_):
                             "L-00020001",
                         ],
                         "cover_image": "image",
+                        "organization_highlighted": "Org 32",
                         "organizations": ["P-00030002", "P-00030003", "L-000300020001"],
                         "state": {
                             "priority": 0,
@@ -365,6 +371,7 @@ def test_query_courses_match_all(self, *_):
                             "L-00020002",
                         ],
                         "cover_image": "image",
+                        "organization_highlighted": "Org 32",
                         "organizations": ["P-00030002", "P-00030004", "L-000300020002"],
                         "state": {
                             "priority": 1,
@@ -386,6 +393,7 @@ def test_query_courses_match_all(self, *_):
                             "L-00020003",
                         ],
                         "cover_image": "image",
+                        "organization_highlighted": "Org 31",
                         "organizations": ["P-00030001", "P-00030003", "L-000300010002"],
                         "state": {
                             "priority": 4,
diff --git a/tests/apps/search/test_query_courses_edge_cases.py b/tests/apps/search/test_query_courses_edge_cases.py
--- a/tests/apps/search/test_query_courses_edge_cases.py
+++ b/tests/apps/search/test_query_courses_edge_cases.py
@@ -136,14 +136,15 @@ def test_query_courses_rare_facet_force(self, *_):
         self.prepare_index(
             [
                 {
-                    "id": index,
-                    "organizations": [id],
-                    "categories": [],
-                    "is_new": False,
                     "absolute_url": {"en": "url"},
+                    "categories": [],
+                    "course_runs": [],
                     "cover_image": {"en": "image"},
+                    "id": index,
+                    "is_new": False,
+                    "organizations": [id],
+                    "organizations_names": {"en": ["Org #{:s}".format(id)]},
                     "title": {"en": "title"},
-                    "course_runs": [],
                 }
                 for index, id in enumerate(organizations)
             ]
@@ -211,16 +212,17 @@ def test_query_courses_rare_facet_no_include_match(self, *_):
         self.prepare_index(
             [
                 {
+                    "absolute_url": {"en": "url"},
+                    "categories": [],
+                    "course_runs": [],
+                    "cover_image": {"en": "image"},
                     "id": index,
+                    "is_new": False,
                     "organizations": random.sample(
                         organizations, random.randint(1, len(organizations))
                     ),
-                    "categories": [],
-                    "is_new": False,
-                    "absolute_url": {"en": "url"},
-                    "cover_image": {"en": "image"},
+                    "organizations_names": {"en": ["Org #{:s}".format(id)]},
                     "title": {"en": "title"},
-                    "course_runs": [],
                 }
                 for index, id in enumerate(organizations)
             ]
diff --git a/tests/apps/search/test_viewsets_courses.py b/tests/apps/search/test_viewsets_courses.py
--- a/tests/apps/search/test_viewsets_courses.py
+++ b/tests/apps/search/test_viewsets_courses.py
@@ -253,6 +253,7 @@ def mock_search_implementation(index, **_):
                 "categories",
                 "cover_image",
                 "organizations",
+                "organizations_names",
                 "title.*",
             ],
             body={