Mvolz has uploaded a new change for review.

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

Change subject: Fix: Stop crashes when PMID and PCMIDs are entered
......................................................................

Fix: Stop crashes when PMID and PCMIDs are entered

* Add test for pmid input

* Fixed errors in CitoidService.prototype.requestFromPubMedID
which used the wrong instance of 'this'

Bug: T93335
Change-Id: I98205962845437d1f65d54fe62a9e28101665741
---
M lib/CitoidService.js
M test/index.js
2 files changed, 31 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/citoid 
refs/changes/04/198204/1

diff --git a/lib/CitoidService.js b/lib/CitoidService.js
index adae651..25a6065 100644
--- a/lib/CitoidService.js
+++ b/lib/CitoidService.js
@@ -129,14 +129,15 @@
  * @param  {Function} callback   callback (error, statusCode, body)
  */
 CitoidService.prototype.requestFromPubMedID = function(opts, callback){
+    var citoidService = this;
     pubMedRequest(opts.search, function(error, obj){
                if(error){
                        callback(error, null, null);
                } else {
                        var doi = obj.records[0].doi;
-                       this.log.info("Got DOI " + doi);
+                       citoidService.log.info("Got DOI " + doi);
                        opts.search = doi;
-                       this.requestFromDOI(opts, callback);
+                       citoidService.requestFromDOI(opts, callback);
                }
        });
 };
diff --git a/test/index.js b/test/index.js
index 97366ac..cc7985c 100644
--- a/test/index.js
+++ b/test/index.js
@@ -37,6 +37,34 @@
 
 citoidService = new CitoidService(citoidConfig, log);
 
+describe('pmid', function() {
+
+       var opts = {
+               search : '23555203',
+               format : 'mediawiki',
+               acceptLanguage : 'en'
+       },
+               expectedTitle = 'Viral Phylodynamics';
+
+       it('should scrape info successfully', function(done) {
+               citoidService.request(opts, function(error, responseCode, 
citation){
+                       if (error) {throw error;}
+                       if (responseCode !== 200){
+                               throw new Error('Not successful: Response code 
is' + responseCode);
+                       }
+                       if (!citation) {throw new Error ('Empty body');}
+                       if (citation[0].title !== expectedTitle){
+                               throw new Error('Expected title is: ' + 
expectedTitle +
+                                       ";\nGot: " + citation[0].title);
+                       }
+                       if (!citation[0].itemType){
+                               throw new Error('Missing itemType');
+                       }
+                       done();
+               });
+       });
+});
+
 describe('200', function() {
 
        var opts = {

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I98205962845437d1f65d54fe62a9e28101665741
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/citoid
Gerrit-Branch: master
Gerrit-Owner: Mvolz <mv...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to