Mvolz has uploaded a new change for review.

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

Change subject: Add source field in mediawiki format
......................................................................

Add source field in mediawiki format

Add 'source' field with value type Array to mediawiki format.

This indicates the source of the retrieved metadata. This
is returned in an Array as multiple sources of metadata
may be present. This currently includes 'WorldCat',
'Crossref', 'Zotero', and 'PubMed' where the PMC/PMID to DOI
API is used. If an empty Array is returned, it can be
assumed that any metadata was retrieved from metadata
directy scraped from the source URL. Zotero results may
include metadata retrieved from CrossRef, WorldCat, and
others.

* Move multiple tests which previously were not in Zotero
to test/features/scraping/noZotero.js as they are now
in Zotero and need Zotero to be disabled to work
* Check source type for multiple scraper tests.

Bug: T145465
Change-Id: I44eec8a77f3c0893aefd917261c4423b49fe17bc
---
M lib/CitoidRequest.js
M lib/CitoidResponse.js
M lib/CitoidService.js
M lib/Exporter.js
M lib/Scraper.js
M test/features/scraping/export.js
M test/features/scraping/index.js
M test/features/scraping/isbn.js
M test/features/scraping/noZotero.js
M test/utils/assert.js
10 files changed, 122 insertions(+), 80 deletions(-)


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

diff --git a/lib/CitoidRequest.js b/lib/CitoidRequest.js
index 624e6af..e34becc 100644
--- a/lib/CitoidRequest.js
+++ b/lib/CitoidRequest.js
@@ -19,6 +19,7 @@
     this.logger = req.logger || app.logger;
 
     this.response = new CitoidResponse(); // Prepare an empty response
+    this.source = []; // Array of sources of the metadata, i.e. CrossRef, 
WorldCat, Zotero, etc.
 
     this.idType = null;
     this.idValue = null;
diff --git a/lib/CitoidResponse.js b/lib/CitoidResponse.js
index 2f516bd..b41e092 100644
--- a/lib/CitoidResponse.js
+++ b/lib/CitoidResponse.js
@@ -10,6 +10,7 @@
 function CitoidResponse() {
 
     this.citation = [{}]; // Initialise empty native citation list with 
initial empty citation
+    this.source = []; // Array of sources of the metadata, i.e. CrossRef, 
WorldCat, Zotero, etc.
     this.responseCode = 500; // Default internal server error
     this.error = null;
     this.body = null;
diff --git a/lib/CitoidService.js b/lib/CitoidService.js
index fd51998..bfaae2a 100644
--- a/lib/CitoidService.js
+++ b/lib/CitoidService.js
@@ -227,6 +227,7 @@
         function (res) {
             res.body = JSON.parse(res.body);
             if (res && res.status === 200 && res.body.stat === 'ok') {
+                cr.response.source.push('WorldCat'); // Add WorldCat as a 
source of the metadata
                 return citoidService.scrapeJSON(cr, res.body);
             } else {
                 return reject(cr);
@@ -268,6 +269,7 @@
 
         function onResolve(cr){
             logger.log('debug/zotero', "Successfully retrieved body from 
Zotero");
+            cr.response.source.push('Zotero'); // Add Zotero as a source of 
the metadata
             return cr;
         }
 
@@ -444,6 +446,7 @@
             cr.doi = doi;
             if (doi){
                 cr.doi = doi;
+                cr.response.source.push('PubMed'); // Add PubMed to sources of 
metadata as we used them to get DOI
                 return self.requestFromDOI(cr).catch(function(){
                     return failure(cr);
                 });
@@ -456,6 +459,7 @@
     }
 
     function onResolve(cr){
+        cr.response.source.push('Zotero'); // Add Zotero as source of metadata
         logger.log('debug/zotero', "Successfully retrieved body from Zotero");
         return cr;
     }
diff --git a/lib/Exporter.js b/lib/Exporter.js
index 3cc9007..e810439 100644
--- a/lib/Exporter.js
+++ b/lib/Exporter.js
@@ -133,13 +133,17 @@
     citation = fixISBN(citation);
     citation = fixISSN(citation);
 
-    return addIDSToCitation(cr, citation).then(function(cit){
+    cr.response.body = [citation]; // Put modified citation in body field
+
+    return addIDSToCitation(cr).then(function(citoidRequest){
         // Convert to baseFields if this was in the request
-        if (cr.baseFields){
-            cit = self.convertToBaseFields(cit);
+        if (citoidRequest.baseFields){
+            citoidRequest.response.body[0] = 
self.convertToBaseFields(citoidRequest.response.body[0]);
         }
-        cr.response.body = [cit];
-        return cr;
+        if (citoidRequest.response.source && 
(citoidRequest.response.source.length > 0)){ // Only add source field if one or 
more source listed
+            citoidRequest.response.body[0].source = 
citoidRequest.response.source; // Add sources field to citation body
+        }
+        return citoidRequest;
     });
 
 });
@@ -186,10 +190,8 @@
 
     citation = fixCreatorsMW(citation);
 
-    return addIDSToCitation(cr, citation).then(function(cit){
-        cr.response.body = [cit];
-        return cr;
-    });
+    cr.response.body = [citation]; // Add citation to body before sending to 
the below function which further fixes body
+    return addIDSToCitation(cr);
 
 });
 
@@ -261,10 +263,13 @@
 
 /**
  * Add PMID, PMCID, and DOI fields from the extra field or through PMID, PMCID 
or DOI lookup
- * @param  {Object}   citation citation object to add PMID
- * @return {Object}   promise for citation object
+ * @param  {Object}   cw      citoidRequest object to add PMID
+ * @return {Object}   promise for citoidRequest object
  */
-var addPubMedIdentifiers = BBPromise.method(function(citation){
+var addPubMedIdentifiers = BBPromise.method(function(cr){
+    var citation = cr.response.citation[0];
+    var gotData = false; // Whether or not we retrieved any useful data from 
PubMed
+
     // Try to get PMCID or PMID from extra field
     if ((!citation.PMCID || !citation.PMID) && citation.extra) {
         //get pmid from extra fields
@@ -280,23 +285,29 @@
 
     if ((citation.PMID !== undefined && citation.PMCID !== undefined && 
citation.DOI !== undefined) || // All IDs present
         (citation.PMID === undefined && citation.PMCID === undefined && 
citation.DOI === undefined)) { // No IDs present
-        return citation;
+        return cr;
     }
 
     // Fill in remaining IDs from pubmed api
     return pubMedRequest((citation.DOI || citation.PMCID || citation.PMID), 
userAgent, defaultLogger).then(function(results){
         if (!citation.PMID && results.records[0].pmid){
+            gotData = true;
             citation.PMID = results.records[0].pmid;
         }
         if (!citation.PMCID && results.records[0].pmcid) {
+            gotData = true;
             citation.PMCID = results.records[0].pmcid.replace('PMC','');
         }
         if (!citation.DOI && results.records[0].doi) {
+            gotData = true;
             citation.DOI = results.records[0].doi;
         }
-        return citation;
+        if ((cr.response.source.indexOf('PubMed') === -1) && gotData){ // Only 
add if PubMed not already in source Array
+            cr.response.source.push('PubMed'); // Add pubmed to source list as 
we retrieved data from there
+        }
+        return cr;
     }, function(){
-        return citation; //Unhandled rejection
+        return cr; //Unhandled rejection
     });
 
 });
@@ -463,12 +474,18 @@
 
 /**
  * Add all identifiers in CitoidRequest to an intermediate
- * converted citation that will be added to body
+ * converted citation currently in body Array.
  * @param  {Object} cr       CitoidRequest object
  * @param  {Object} citation citation object
- * @return {Object}          citation object
+ * @return {Object}          CitoidRequest object
  */
-var addIDSToCitation = BBPromise.method(function(cr, citation){
+var addIDSToCitation = BBPromise.method(function(cr){
+    // Fill body if not done already
+    if (!cr.response.body || !cr.response.body[0]){ // If body is null or 
empty array, set to citation field
+        cr.response.body = cr.response.citation;
+    }
+    // Pointer for code clarity
+    var citation = cr.response.body[0];
 
     // Set requested identifier as part of citation
     if (cr.idType !== 'url' && !citation[cr.idType.toUpperCase()]) {
@@ -480,7 +497,7 @@
         citation.DOI = cr.doi;
     }
 
-    return addPubMedIdentifiers(citation);
+    return addPubMedIdentifiers(cr);
 
 });
 
diff --git a/lib/Scraper.js b/lib/Scraper.js
index ab50e19..66165ce 100644
--- a/lib/Scraper.js
+++ b/lib/Scraper.js
@@ -273,8 +273,8 @@
                 cr.doi = metadata.bePress.doi.match(reDOI)[0];
             }
         }
-        return crossRef(cr, metadata).then(function(cit){
-            return addMetadata(metadata, cit);
+        return crossRef(cr).then(function(citoidRequest){
+            return addMetadata(metadata, citoidRequest.response.citation[0]);
         },
         // Rejection handler for crossRef
         function(){
@@ -295,7 +295,7 @@
  * @param  {Object} cr     CitoidRequest instance
  * @return {Object}        BBPromise for citation object
  */
-var crossRef = BBPromise.method(function(cr, metadata){
+var crossRef = BBPromise.method(function(cr){
     var citation = cr.response.citation[0] = cr.response.citation[0] || {};
     var doi = cr.doi;
     var translate = defaultTranslator.translate;
@@ -331,12 +331,12 @@
         delete typeTranslator.date; // The date field from crossRef only 
contains the year, which results in the month being wrong
         citation = translate(citation, metadata, typeTranslator);
 
-
-        return citation;
+        cr.response.source.push('Crossref');
+        return cr;
     // Rejection handler
     }, function(){
         defaultLogger.log('debug/scraper', "Failed to get crossRef data");
-        return citation;
+        return cr;
     });
 });
 
@@ -447,9 +447,10 @@
         return citation;
     }
 
-    return crossRef(cr, citation).then(function(cit){
-        citation = fallback520(cit, 200);
+    return crossRef(cr).then(function(citoidRequest){
+        citoidRequest.response.citation[0] = 
fallback520(citoidRequest.response.citation[0], 200);
         defaultLogger.log('debug/scraper', "Sucessfully got metadata from doi 
" + cr.doi);
+        return citoidRequest;
     // Rejection
     }, function(){
         defaultLogger.log('info/scraper', "Unable to get any metadata from doi 
" + cr.doi + "; returning 520 response.");
diff --git a/test/features/scraping/export.js b/test/features/scraping/export.js
index fbf811e..c44c10d 100644
--- a/test/features/scraping/export.js
+++ b/test/features/scraping/export.js
@@ -40,7 +40,9 @@
         it('doi pointing to bookSection', function() {
             return server.query('10.1007/11926078_68', 
'zotero').then(function(res) {
                 assert.status(res, 200);
-                assert.checkZotCitation(res, 'Semantic MediaWiki');
+                assert.checkCitation(res, 'Semantic MediaWiki');
+                assert.deepEqual(!!res.body[0].accessDate, true, 'No 
accessDate present');
+                assert.notDeepEqual(res.body[0].accessDate, 
'CURRENT_TIMESTAMP', 'Access date uncorrected');
                 assert.ok(res.body[0].creators);
                 assert.deepEqual(res.body[0].DOI, undefined, 'DOI is invalid 
field for type bookSection');
                 assert.deepEqual(res.body[0].itemType, 'bookSection', 'Wrong 
itemType; expected bookSection, got' + res.body[0].itemType);
@@ -52,7 +54,9 @@
         it('doi pointing to bookSection', function() {
             return server.query('10.1007/11926078_68', 
'mwDeprecated').then(function(res) {
                 assert.status(res, 200);
-                assert.checkZotCitation(res, 'Semantic MediaWiki');
+                assert.checkCitation(res, 'Semantic MediaWiki');
+                assert.deepEqual(!!res.body[0].accessDate, true, 'No 
accessDate present');
+                assert.notDeepEqual(res.body[0].accessDate, 
'CURRENT_TIMESTAMP', 'Access date uncorrected');
                 assert.ok(res.body[0]['author1-last']);
                 assert.ok(res.body[0].DOI);
                 assert.deepEqual(res.body[0].itemType, 'bookSection', 'Wrong 
itemType; expected bookSection, got' + res.body[0].itemType);
@@ -61,7 +65,9 @@
         it('doi pointing to Zotero gotten response with name field instead of 
lastName in creators object', function() {
             return server.query('10.1001/jama.296.10.1274', 
'mwDeprecated').then(function(res) {
                 assert.status(res, 200);
-                assert.checkZotCitation(res, 'DOes this patient with headache 
have a migraine or need neuroimaging?');
+                assert.checkCitation(res, 'DOes this patient with headache 
have a migraine or need neuroimaging?');
+                assert.deepEqual(!!res.body[0].accessDate, true, 'No 
accessDate present');
+                assert.notDeepEqual(res.body[0].accessDate, 
'CURRENT_TIMESTAMP', 'Access date uncorrected');
                 assert.ok(res.body[0]['author1-last']);
                 assert.ok(res.body[0].DOI);
                 assert.deepEqual(res.body[0].itemType, 'journalArticle', 
'Wrong itemType; expected journalArticle, got' + res.body[0].itemType);
diff --git a/test/features/scraping/index.js b/test/features/scraping/index.js
index e8ce812..398a0ba 100644
--- a/test/features/scraping/index.js
+++ b/test/features/scraping/index.js
@@ -244,6 +244,7 @@
         it('example domain', function() {
             return server.query('example.com').then(function(res) {
                 assert.status(res, 200);
+                assert.deepEqual(res.body[0].source, undefined);
                 assert.checkCitation(res, 'Example Domain');
                 assert.deepEqual(!!res.body[0].accessDate, true, 'No 
accessDate present');
             });
@@ -254,6 +255,7 @@
             var url = 'http://www.google.com';
             return server.query(url).then(function(res) {
                 assert.status(res, 200);
+                assert.deepEqual(res.body[0].source, undefined);
                 assert.checkCitation(res, 'Google');
                 assert.deepEqual(!!res.body[0].accessDate, true, 'No 
accessDate present');
                 assert.deepEqual(res.body[0].url, url);
@@ -264,62 +266,19 @@
             return 
server.query('http://blog.woorank.com/2013/04/dublin-core-metadata-for-seo-and-usability/').then(function(res)
 {
                 assert.status(res, 200);
                 assert.checkCitation(res);
+                assert.deepEqual(res.body[0].source, undefined);
                 assert.deepEqual(!!res.body[0].accessDate, true, 'No 
accessDate present');
                 assert.deepEqual(!!res.body[0].websiteTitle, true, 'Missing 
websiteTitle field');
                 assert.deepEqual(res.body[0].publicationTitle, undefined, 
'Invalid field publicationTitle');
             });
         });
 
-        it('requires cookie handling', function() {
-            return 
server.query('www.jstor.org/discover/10.2307/3677029').then(function(res) {
-                assert.status(res, 200);
-                assert.checkCitation(res);
-                assert.deepEqual(!!res.body[0].accessDate, true, 'No 
accessDate present');
-            });
-        });
-
         // Ensure DOI is present in non-zotero scraped page when requested 
from DOI
-        it('DOI pointing to resource not in zotero', function() {
+        it.skip('DOI pointing to resource not in zotero', function() { // 
Currently this *is* in Zotero, so we need a new DOI that is not in Zotero
             return server.query('10.2307/3677029').then(function(res) {
                 assert.status(res, 200);
                 assert.checkCitation(res);
-                assert.deepEqual(!!res.body[0].DOI, true, 'Missing DOI');
-                assert.deepEqual(res.body[0].websiteTitle, undefined, 
'Unexpected field websiteTitle');
-                assert.deepEqual(res.body[0].itemType, 'journalArticle', 
'Wrong itemType; expected journalArticle, got' + res.body[0].itemType);
-            });
-        });
-
-        // Ensure DOI is present in non-zotero scraped page when request from 
DOI link
-        it('dx.DOI link pointing to resource not in zotero - uses crossRef', 
function() {
-            return 
server.query('http://dx.DOI.org/10.2307/3677029').then(function(res) {
-                assert.status(res, 200);
-                assert.checkCitation(res, 'Flight Feather Moult in the 
Red-Necked Nightjar Caprimulgus ruficollis');
-                assert.deepEqual(!!res.body[0].author, true, 'Missing 
authors');
-                assert.deepEqual(!!res.body[0].issue, true, 'Missing issue');
-                assert.deepEqual(!!res.body[0].volume, true, 'Missing volume');
-                assert.deepEqual(!!res.body[0].DOI, true, 'Missing DOI');
-                assert.deepEqual(res.body[0].websiteTitle, undefined, 
'Unexpected field websiteTitle');
-                assert.deepEqual(res.body[0].itemType, 'journalArticle', 
'Wrong itemType; expected journalArticle, got' + res.body[0].itemType);
-            });
-        });
-
-        it('Case sensitive DOI with 5 digit registrant code and unknown genre 
in crossRef', function() {
-            return server.query('10.14344/IOC.ML.4.4').then(function(res) {
-                assert.status(res, 200);
-                assert.checkZotCitation(res, 'IOC World Bird List 4.4');
-                assert.deepEqual(!!res.body[0].DOI, true, 'Missing DOI');
-            });
-        });
-
-        // Ensure DOI is present in non-zotero scraped page where scraping 
fails
-        it('DOI pointing to resource that can\'t be scraped - uses crossRef', 
function() {
-            return server.query('10.1038/scientificamerican0200-90')
-            .then(function(res) {
-                assert.status(res, 200);
-                assert.checkCitation(res);
-                assert.deepEqual(!!res.body[0].author, true, 'Missing 
authors');
-                assert.deepEqual(!!res.body[0].issue, true, 'Missing issue');
-                assert.deepEqual(!!res.body[0].volume, true, 'Missing volume');
+                assert.deepEqual(res.body[0].source, undefined);
                 assert.deepEqual(!!res.body[0].DOI, true, 'Missing DOI');
                 assert.deepEqual(res.body[0].websiteTitle, undefined, 
'Unexpected field websiteTitle');
                 assert.deepEqual(res.body[0].itemType, 'journalArticle', 
'Wrong itemType; expected journalArticle, got' + res.body[0].itemType);
@@ -330,6 +289,7 @@
         it('doi in url with query parameters - uses crossRef', function() {
             return 
server.query('http://www.example.com/10.1086/378695?uid=3739832&uid=2&uid=4&uid=3739256&sid=21105503736473').then(function(res)
 {
                 assert.status(res, 200);
+                assert.deepEqual(res.body[0].source, 'Crossref');
                 assert.checkCitation(res, 'Salaries, Turnover, and Performance 
in the Federal Criminal Justice System*');
                 assert.deepEqual(res.body[0].DOI, '10.1086/378695');
                 assert.deepEqual(res.body[0].author.length, 1);
@@ -340,7 +300,8 @@
         it('url with pseudo doi', function() {
             return 
server.query('http://g2014results.thecgf.com/athlete/weightlifting/1024088/dika_toua.html').then(function(res)
 {
                 assert.status(res, 200);
-                assert.checkZotCitation(res, 'Glasgow 2014 - Dika Toua 
Profile');
+                assert.deepEqual(res.body[0].source, undefined);
+                assert.checkCitation(res, 'Glasgow 2014 - Dika Toua Profile');
                 assert.deepEqual(!!res.body[0].DOI, false);
             });
         });
diff --git a/test/features/scraping/isbn.js b/test/features/scraping/isbn.js
index e88e0cd..06d0040 100644
--- a/test/features/scraping/isbn.js
+++ b/test/features/scraping/isbn.js
@@ -20,6 +20,7 @@
         return server.query('978-0-596-51979-7').then(function(res) {
             assert.status(res, 200);
             assert.checkCitation(res, 'MediaWiki');
+            assert.deepEqual(res.body[0].source[0], 'WorldCat');
             assert.deepEqual(res.body[0].author, [['Daniel J.', 'Barrett']], 
'Unexpected value; expected [[\'Daniel J.\'], [\'Barrett.\']] ' + 
res.body[0].author);
             assert.deepEqual(res.body[0].publisher, 'O\'Reilly Media', 
'Unexpected value; expected O\'Reilly Media, got ' + res.body[0].publisher);
             assert.deepEqual(res.body[0].place, 'Sebastapool, Calif.', 
'Unexpected value; expected Sebastapool, Calif., got ' + res.body[0].place);
@@ -34,6 +35,7 @@
         return server.query('9780439784542').then(function(res) {
             assert.status(res, 200);
             assert.checkCitation(res, 'Harry Potter and the half-blood 
prince');
+            assert.deepEqual(res.body[0].source[0], 'WorldCat');
             assert.deepEqual(res.body[0].author, [['J.K.', 'Rowling']], 
'Unexpected value; expected [[\'J.K.\', \'Rowling\']] got ' + 
res.body[0].author);
             assert.deepEqual(res.body[0].place, 'New York, NY', 'Unexpected 
value; expected New York, NY, got ' + res.body[0].place);
             assert.deepEqual(res.body[0].edition, '1st American ed.', 
'Unexpected value; expected 1st ed., got ' + res.body[0].edition);
diff --git a/test/features/scraping/noZotero.js 
b/test/features/scraping/noZotero.js
index bd79149..07ae4e6 100644
--- a/test/features/scraping/noZotero.js
+++ b/test/features/scraping/noZotero.js
@@ -67,7 +67,7 @@
     it('doi spage and epage fields in crossRef coins data', function() {
         return 
server.query('http://dx.doi.org/10.1002/jlac.18571010113').then(function(res) {
             assert.status(res, 200);
-            assert.checkZotCitation(res, 'Ueber einige Derivate des 
Naphtylamins');
+            assert.checkCitation(res, 'Ueber einige Derivate des 
Naphtylamins');
             assert.deepEqual(!!res.body[0].DOI, true, 'Missing DOI');
             assert.deepEqual(res.body[0].pages, '90–93', 'Missing pages'); // 
Uses en dash
             assert.deepEqual(res.body[0].itemType, 'journalArticle', 'Wrong 
itemType; expected journalArticle, got' + res.body[0].itemType);
@@ -78,7 +78,7 @@
     it('successfully uses highwire press metadata', function() {
         return 
server.query('http://mic.microbiologyresearch.org/content/journal/micro/10.1099/mic.0.082289-0').then(function(res)
 {
             assert.status(res, 200);
-            assert.checkZotCitation(res, 'Resistance to bacteriocins produced 
by Gram-positive bacteria');
+            assert.checkCitation(res, 'Resistance to bacteriocins produced by 
Gram-positive bacteria');
             assert.deepEqual(!!res.body[0].DOI, true, 'Missing DOI');
             assert.deepEqual(!!res.body[0].ISSN, true, 'Missing ISSN'); // 
Comes from highwire
             assert.deepEqual(res.body[0].author.length, 3, 'Should have 3 
authors');
@@ -92,7 +92,7 @@
     it('successfully uses bepress press metadata', function() {
         return 
server.query('http://uknowledge.uky.edu/upk_african_history/1/').then(function(res)
 {
             assert.status(res, 200);
-            assert.checkZotCitation(res, 'South Africa and the World: The 
Foreign Policy of Apartheid');
+            assert.checkCitation(res, 'South Africa and the World: The Foreign 
Policy of Apartheid');
             assert.deepEqual(res.body[0].author.length, 1, 'Should have 1 
author');
             assert.deepEqual(res.body[0].date, '1970-01-01', 'Incorrect or 
missing date'); // Comes from highwire
             assert.deepEqual(res.body[0].itemType, 'journalArticle', 'Wrong 
itemType; expected journalArticle, got' + res.body[0].itemType); // Actually is 
a book but no way to tell from metadata :(
@@ -122,4 +122,52 @@
         });
     });
 
+    it('requires cookie handling', function() {
+        return 
server.query('www.jstor.org/discover/10.2307/3677029').then(function(res) {
+            assert.status(res, 200);
+            assert.deepEqual(res.body[0].source[0], 'Crossref');
+            assert.checkCitation(res);
+            assert.deepEqual(!!res.body[0].accessDate, true, 'No accessDate 
present');
+        });
+    });
+
+    // Ensure DOI is present in non-zotero scraped page where scraping fails
+    it('DOI pointing to resource that can\'t be scraped - uses crossRef', 
function() {
+        return server.query('10.1038/scientificamerican0200-90')
+        .then(function(res) {
+            assert.status(res, 200);
+            assert.checkCitation(res);
+            assert.deepEqual(res.body[0].source, 'Crossref');
+            assert.deepEqual(!!res.body[0].author, true, 'Missing authors');
+            assert.deepEqual(!!res.body[0].issue, true, 'Missing issue');
+            assert.deepEqual(!!res.body[0].volume, true, 'Missing volume');
+            assert.deepEqual(!!res.body[0].DOI, true, 'Missing DOI');
+            assert.deepEqual(res.body[0].websiteTitle, undefined, 'Unexpected 
field websiteTitle');
+            assert.deepEqual(res.body[0].itemType, 'journalArticle', 'Wrong 
itemType; expected journalArticle, got' + res.body[0].itemType);
+        });
+    });
+
+    // Ensure DOI is present in non-zotero scraped page when request from DOI 
link
+    it('dx.DOI link - uses crossRef', function() {
+        return 
server.query('http://dx.DOI.org/10.2307/3677029').then(function(res) {
+            assert.status(res, 200);
+            assert.deepEqual(res.body[0].source, 'Crossref');
+            assert.checkCitation(res, 'Flight Feather Moult in the Red-Necked 
Nightjar Caprimulgus ruficollis');
+            assert.deepEqual(!!res.body[0].author, true, 'Missing authors');
+            assert.deepEqual(!!res.body[0].issue, true, 'Missing issue');
+            assert.deepEqual(!!res.body[0].volume, true, 'Missing volume');
+            assert.deepEqual(!!res.body[0].DOI, true, 'Missing DOI');
+            assert.deepEqual(res.body[0].websiteTitle, undefined, 'Unexpected 
field websiteTitle');
+            assert.deepEqual(res.body[0].itemType, 'journalArticle', 'Wrong 
itemType; expected journalArticle, got' + res.body[0].itemType);
+        });
+    });
+
+    it('Case sensitive DOI with 5 digit registrant code and unknown genre in 
crossRef', function() {
+        return server.query('10.14344/IOC.ML.4.4').then(function(res) {
+            assert.status(res, 200);
+            assert.deepEqual(res.body[0].source, 'Crossref');
+            assert.checkCitation(res, 'IOC World Bird List 4.4');
+            assert.deepEqual(!!res.body[0].DOI, true, 'Missing DOI');
+        });
+    });
 });
\ No newline at end of file
diff --git a/test/utils/assert.js b/test/utils/assert.js
index 70acbf3..02b2d3a 100644
--- a/test/utils/assert.js
+++ b/test/utils/assert.js
@@ -132,6 +132,7 @@
 
     checkCitation(res, title);
 
+    assert.deepEqual(res.body[0].source[0], 'Zotero'); // TODO: Currently this 
works but in the future might not always be first element
     assert.deepEqual(!!res.body[0].accessDate, true, 'No accessDate present');
     assert.notDeepEqual(res.body[0].accessDate, 'CURRENT_TIMESTAMP', 'Access 
date uncorrected');
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I44eec8a77f3c0893aefd917261c4423b49fe17bc
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