Niedzielski has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/297811

Change subject: Don't return a picture of the day null description
......................................................................

Don't return a picture of the day null description

Sometimes descriptions aren't available. Don't send a language without a
description.

Change-Id: If17f02ef09704293355db508b205d8c34512a409
---
M lib/feed/featured-image.js
M test/features/featured-image/pagecontent.js
M test/utils/assert.js
3 files changed, 30 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/mobileapps 
refs/changes/11/297811/1

diff --git a/lib/feed/featured-image.js b/lib/feed/featured-image.js
index fc46578..dee1128 100644
--- a/lib/feed/featured-image.js
+++ b/lib/feed/featured-image.js
@@ -69,7 +69,7 @@
     lang = allDescriptions[lang] ? lang : 'en';
     let description = allDescriptions[lang];
 
-    return {
+    let ret = {
         title: page.title,
         thumbnail: {
             source: imageinfo && imageinfo.thumburl,
@@ -81,12 +81,15 @@
             source: imageinfo.url,
             width: imageinfo.width,
             height: imageinfo.height
-        },
-        description: {
-            text: description,
-            lang: lang
         }
     };
+    if (description) {
+        ret.description = {
+            text: description,
+            lang: lang
+        };
+    }
+    return ret;
 }
 
 function buildEtag(page) {
diff --git a/test/features/featured-image/pagecontent.js 
b/test/features/featured-image/pagecontent.js
index 1ad06b2..8ddc088 100644
--- a/test/features/featured-image/pagecontent.js
+++ b/test/features/featured-image/pagecontent.js
@@ -55,6 +55,13 @@
                  });
     });
 
+    it('should return no description when unavailable', function() {
+             return preq.get({ uri: server.config.uri + 
'en.wikipedia.org/v1/media/image/featured/2016/06/15' })
+            .then(function(res) {
+                assert.notProperty(res.body, 'description');
+                 });
+    });
+
     it('featured image of an old date should return 404', function() {
         return preq.get({ uri: server.config.uri + 
'en.wikipedia.org/v1/media/image/featured/1970/12/31' })
             .then(function(res) {
diff --git a/test/utils/assert.js b/test/utils/assert.js
index 38c767c..7771eeb 100644
--- a/test/utils/assert.js
+++ b/test/utils/assert.js
@@ -73,6 +73,19 @@
 }
 
 
+function property(object, property) {
+    const msg = `expected property="${property}"`;
+    assert.ok(object, msg);
+    assert.ok(object.hasOwnProperty(property), msg);
+}
+
+
+function notProperty(object, property) {
+    assert.ok(!object || !object.hasOwnProperty(property),
+        `unexpected property="${property}"`);
+}
+
+
 function fails(promise, onRejected) {
 
     var failed = false;
@@ -150,6 +163,8 @@
 module.exports.deepEqual      = deepEqual;
 module.exports.isDeepEqual    = isDeepEqual;
 module.exports.notDeepEqual   = notDeepEqual;
+module.exports.property       = property;
+module.exports.notProperty    = notProperty;
 module.exports.contentType    = contentType;
 module.exports.status         = status;
 module.exports.contains       = contains;

-- 
To view, visit https://gerrit.wikimedia.org/r/297811
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: If17f02ef09704293355db508b205d8c34512a409
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/mobileapps
Gerrit-Branch: master
Gerrit-Owner: Niedzielski <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to