Mvolz has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/350558 )
Change subject: [WIP] Support search for arbitrary strings
......................................................................
[WIP] Support search for arbitrary strings
Add support for search of arbitrary
strings using WorldCat OpenSearch library.
Change-Id: Icfd15e4a22a9ae5b2d25084a2476097d896f24db
---
M lib/Citation.js
M lib/CitoidService.js
M lib/XMLReader.js
A test/features/scraping/worldcat.js
4 files changed, 421 insertions(+), 161 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/citoid
refs/changes/58/350558/1
diff --git a/lib/Citation.js b/lib/Citation.js
index 6a58812..2dc43ca 100644
--- a/lib/Citation.js
+++ b/lib/Citation.js
@@ -20,6 +20,7 @@
this.pmcid = (this.idType === 'pmcid') ? this.idValue : null;
this.pmid = (this.idType === 'pmid') ? this.idValue : null;
this.isbn = (this.idType === 'isbn') ? this.idValue : null;
+ this.other = (this.idType === 'other') ? this.idValue : null;
this.content = {}; // Initialise empty object for fields
this.format = null; // Target format
diff --git a/lib/CitoidService.js b/lib/CitoidService.js
index cc31fe0..d07cae0 100644
--- a/lib/CitoidService.js
+++ b/lib/CitoidService.js
@@ -203,136 +203,19 @@
}
}
- // Assume url if no other matches are made
+ // Case: Unknown input
+ // TODO: Possible try CrossRef
+
+ // Try worldcat open search
+ logger.log('debug/CitoidService', "URI detected");
+ cit = new Citation('other', idValue);
+ cr.response.citations.push(cit);
+ cr.getResults.push(self.requestToOpenSearch(cit, cr));
+ self.stats.increment('input.other');
+ // Also try url
return foundURI(url);
});
-
-/**
- * Promise of requested citation metadata from an ISBN. Uses worldcat xISBN
service.
- * @param {Object} cr CitoidRequest object with new functions added to
getResults Array
- * @return {Object} BBPromise object for modified CitoidRequest
object from input
- */
-CitoidService.prototype.requestToXISBN = function(citation, cr) {
- this.logger.log('debug/CitoidService', "requestToXISBN method");
- citation.format = cr.format;
- citation.doi = cr.doi;
-
- var isbnLink = 'http://xisbn.worldcat.org/webservices/xid/isbn/'+
citation.isbn;
- var citoidService = this;
-
- var query = { // Basic query parameters
- method: 'getMetadata',
- format: 'json',
- fl:'*'
- };
-
- var requestOptions = {
- uri : isbnLink,
- headers: {
- 'User-Agent': this.userAgent
- },
- qs: query
- };
-
- // Set responses if below is rejected
- function reject(cit){
- var message = 'Unable to retrieve data from ISBN ' + cit.isbn;
- var error = {Error: message};
- citoidService.logger.log('debug/ISBN', message);
-
- cit.error = error;
- cit.responseCode = 404;
-
- return cr;
- }
-
- // Make request to WorldCat xisbn service
- return preq(requestOptions).then(
- function (res) {
- res.body = JSON.parse(res.body);
- if (res && res.status === 200 && res.body.stat === 'ok') {
- // Add oclc number to the request object
- if (res.body.list && res.body.list[0] &&
res.body.list[0].oclcnum &&
- res.body.list[0].oclcnum[0] && typeof
res.body.list[0].oclcnum[0] === 'string') {
- cr.oclc = res.body.list[0].oclcnum[0];
- citation.oclc = res.body.list[0].oclcnum[0];
- }
- // Add WorldCat as a source of the metadata
- citation.source.push('WorldCat');
-
- return citoidService.scrapeJSON(citation, cr, res.body);
- } else {
- return reject(citation);
- }
- },
- // Preq rejection handler
- function(res){
- return reject(citation);
- }
- );
-
-};
-
-/**
- * Promise of requested citation metadata from an ISBN. Uses worldcat search
API
- * @param {Object} cr CitoidRequest object with new functions added to
getResults Array
- * @return {Object} BBPromise object for modified CitoidRequest
object from input
- */
-CitoidService.prototype.requestToWSKEY = function(citation, cr) {
- this.logger.log('debug/CitoidService', "requestToWSKEY method");
- citation.format = cr.format;
- citation.doi = cr.doi;
-
- var isbnLink = 'http://www.worldcat.org/webservices/catalog/search/sru';
- var citoidService = this;
- var zotero = this.conf.zotero;
-
- var query = { // Basic query parameters
- query: 'srw.bn+all+' + citation.isbn, // Don't url encode
- recordSchema: 'info%3Asrw%2Fschema%2F1%2Fdc', // Already url encoded
- wskey: citoidService.conf.wskey
- };
-
- var requestOptions = {
- uri : isbnLink,
- headers: {
- 'User-Agent': citoidService.userAgent
- },
- qs: query,
- qsStringifyOptions: { // Prevent query strings from being URL encoded
- encode: false
- }
- };
-
- // Set responses if below is rejected
- function reject(){
- var message = 'Unable to retrieve data from ISBN ' + citation.isbn;
- var error = {Error: message};
- cr.logger.log('debug/ISBN', message);
-
- citation.error = error;
- citation.responseCode = 404;
-
- return cr;
- }
-
- // Make request to WorldCat xisbn service
- return preq(requestOptions).then(
- function (res) {
- if (res && res.status === 200) {
- return citoidService.scrapeXML(citation, cr, res.body);
- } else {
- return reject();
- }
- },
- // Preq rejection handler
- function(res){
- return reject();
- }
- );
-
-};
/**
* Promise of requested citation metadata from a URL
@@ -509,6 +392,7 @@
},
// Preq rejection handler
function(res){
+ console.log(res);
return reject(cr);
});
};
@@ -629,9 +513,194 @@
};
/**
+ * Promise of requested citation metadata from an ISBN. Uses worldcat search
API
+ * @param {Object} cr CitoidRequest object with new functions added to
getResults Array
+ * @return {Object} BBPromise object for modified CitoidRequest
object from input
+ */
+CitoidService.prototype.requestToOpenSearch = function(citation, cr) {
+ this.logger.log('debug/CitoidService', "requestToOpenSearch method");
+ citation.format = cr.format;
+ citation.doi = cr.doi;
+
+ var wskeyFormat = 'openSearch'; // Format the XML citation will come back
in. Can be DC, MarcXML, or WorldCat's native openSearch format
+ var openSearchLink =
'http://www.worldcat.org/webservices/catalog/search/worldcat/opensearch';
+ var citoidService = this;
+ var zotero = this.conf.zotero;
+
+ var query = { // Basic query parameters
+ q: citation.other,
+ wskey: citoidService.conf.wskey
+ };
+
+ var requestOptions = {
+ uri : openSearchLink,
+ headers: {
+ 'User-Agent': citoidService.userAgent
+ },
+ qs: query
+ };
+
+ // Set responses if below is rejected
+ function reject(){
+ var message = 'Unable to retrieve data from query ' + citation.other;
+ var error = {Error: message};
+ cr.logger.log('debug/other', message);
+
+ citation.error = error;
+ citation.responseCode = 404;
+
+ return cr;
+ }
+
+ // Make request to WorldCat xisbn service
+ return preq(requestOptions).then(
+ function (res) {
+ if (res && res.status === 200) {
+ return citoidService.scrapeXML(citation, cr, res.body,
wskeyFormat);
+ } else {
+ return reject();
+ }
+ },
+ // Preq rejection handler
+ function(res){
+ return reject();
+ }
+ );
+
+};
+
+/**
+ * Promise of requested citation metadata from an ISBN. Uses worldcat search
API
+ * @param {Object} cr CitoidRequest object with new functions added to
getResults Array
+ * @return {Object} BBPromise object for modified CitoidRequest
object from input
+ */
+CitoidService.prototype.requestToWSKEY = function(citation, cr) {
+ this.logger.log('debug/CitoidService', "requestToWSKEY method");
+ citation.format = cr.format;
+ citation.doi = cr.doi;
+ var wskeyFormat = 'dc';
+
+ var isbnLink = 'http://www.worldcat.org/webservices/catalog/search/sru';
+ var citoidService = this;
+ var zotero = this.conf.zotero;
+
+ var query = { // Basic query parameters
+ query: 'srw.bn+all+' + citation.isbn, // Don't url encode
+ recordSchema: 'info%3Asrw%2Fschema%2F1%2Fdc', // Already url encoded
+ wskey: citoidService.conf.wskey
+ };
+
+ var requestOptions = {
+ uri : isbnLink,
+ headers: {
+ 'User-Agent': citoidService.userAgent
+ },
+ qs: query,
+ qsStringifyOptions: { // Prevent query strings from being URL encoded
+ encode: false
+ }
+ };
+
+ // Set responses if below is rejected
+ function reject(){
+ var message = 'Unable to retrieve data from ISBN ' + citation.isbn;
+ var error = {Error: message};
+ cr.logger.log('debug/ISBN', message);
+
+ citation.error = error;
+ citation.responseCode = 404;
+
+ return cr;
+ }
+
+ // Make request to WorldCat xisbn service
+ return preq(requestOptions).then(
+ function (res) {
+ if (res && res.status === 200) {
+ return citoidService.scrapeXML(citation, cr, res.body,
wskeyFormat);
+ } else {
+ return reject();
+ }
+ },
+ // Preq rejection handler
+ function(res){
+ return reject();
+ }
+ );
+
+};
+
+/**
+ * Promise of requested citation metadata from an ISBN. Uses worldcat xISBN
service.
+ * @param {Object} cr CitoidRequest object with new functions added to
getResults Array
+ * @return {Object} BBPromise object for modified CitoidRequest
object from input
+ */
+CitoidService.prototype.requestToXISBN = function(citation, cr) {
+ this.logger.log('debug/CitoidService', "requestToXISBN method");
+ citation.format = cr.format;
+ citation.doi = cr.doi;
+
+ var isbnLink = 'http://xisbn.worldcat.org/webservices/xid/isbn/'+
citation.isbn;
+ var citoidService = this;
+
+ var query = { // Basic query parameters
+ method: 'getMetadata',
+ format: 'json',
+ fl:'*'
+ };
+
+ var requestOptions = {
+ uri : isbnLink,
+ headers: {
+ 'User-Agent': this.userAgent
+ },
+ qs: query
+ };
+
+ // Set responses if below is rejected
+ function reject(cit){
+ var message = 'Unable to retrieve data from ISBN ' + cit.isbn;
+ var error = {Error: message};
+ citoidService.logger.log('debug/ISBN', message);
+
+ cit.error = error;
+ cit.responseCode = 404;
+
+ return cr;
+ }
+
+ // Make request to WorldCat xisbn service
+ return preq(requestOptions).then(
+ function (res) {
+ res.body = JSON.parse(res.body);
+ if (res && res.status === 200 && res.body.stat === 'ok') {
+ // Add oclc number to the request object
+ if (res.body.list && res.body.list[0] &&
res.body.list[0].oclcnum &&
+ res.body.list[0].oclcnum[0] && typeof
res.body.list[0].oclcnum[0] === 'string') {
+ cr.oclc = res.body.list[0].oclcnum[0];
+ citation.oclc = res.body.list[0].oclcnum[0];
+ }
+ // Add WorldCat as a source of the metadata
+ citation.source.push('WorldCat');
+
+ return citoidService.scrapeJSON(citation, cr, res.body);
+ } else {
+ return reject(citation);
+ }
+ },
+ // Preq rejection handler
+ function(res){
+ return reject(citation);
+ }
+ );
+
+};
+
+/**
* Scrape and export to Zotero translator if nessecary
- * @param {Object} cr CitoidRequest object
- * @return {Object} BBPromise for CitoidRequest object
+ * @param {Object} citation Citation object
+ * @param {Object} cr CitoidRequest object
+ * @return {Object} BBPromise for CitoidRequest object
*/
CitoidService.prototype.scrapeHTML = function(citation, cr){
return this.scraper.scrape(citation, cr);
@@ -639,9 +708,10 @@
/**
* Convert JSON into citation - currently takes xisbn JSON only
- * @param {Object} cr CitoidRequest object
- * @param {Object} json Object containing JSON to convert into citation
- * @return {Object} BBPromise for CitoidRequest object
+ * @param {Object} citation Citation object
+ * @param {Object} cr CitoidRequest object
+ * @param {Object} json Object containing JSON to convert into
citation
+ * @return {Object} BBPromise for CitoidRequest object
*/
CitoidService.prototype.scrapeJSON = function(citation, cr, json){
return this.json.translate(citation, cr, json);
@@ -649,12 +719,14 @@
/**
* Convert XML into citation - currently takes worldcat search API xml only
- * @param {Object} cr CitoidRequest object
- * @param {Object} xml Raw xml returned in response
- * @return {Object} BBPromise for CitoidRequest object
+ * @param {Object} citation Citation object
+ * @param {Object} cr CitoidRequest object
+ * @param {Object} xml Raw xml returned in response
+ * @param {String} wskeyFormat Format the XML citation will come back
in. Can be 'dc', 'marcXML', or WorldCat's native 'openSearch' format
+ * @return {Object} BBPromise for CitoidRequest object
*/
-CitoidService.prototype.scrapeXML = function(citation, cr, xml){
- return this.xml.translate(citation, cr, xml);
+CitoidService.prototype.scrapeXML = function(citation, cr, xml, wskeyFormat){
+ return this.xml.translate(citation, cr, xml, wskeyFormat);
};
module.exports = CitoidService;
diff --git a/lib/XMLReader.js b/lib/XMLReader.js
index 4982840..f96b376 100644
--- a/lib/XMLReader.js
+++ b/lib/XMLReader.js
@@ -83,46 +83,55 @@
return itemType;
}
-XMLReader.prototype.translate = function(citationObj, cr, xml){
+XMLReader.prototype.translate = function(citationObj, cr, xml, wskeyFormat){
var content = citationObj.content;
var translate = this.translator.translate;
var itemType;
var xmlreader = this;
var record;
- var message = 'Unable to retrieve data from ISBN ' + citationObj.isbn;
- var error = {Error: message};
+ var message;
+ var error;
function reject(){
+ error = {Error: message};
citationObj.responseCode = 404;
citationObj.error = error;
return cr;
}
- return xml2js.parseStringAsync(xml).then(function (result) {
- try {
- if (result.searchRetrieveResponse.records[0].record.length > 0) {
- record =
process(result.searchRetrieveResponse.records[0].record[0].recordData[0].oclcdcs[0]);
- // TODO: Try to get OCLC number
- // Defaults to book
- content.itemType = getItemType(record);
- // dublinCore.js translator properties
- content = translate(content, record, dc[content.itemType]);
- // Add OCLC number to response, url, and oclc fields
- if (record.oclc){
- citationObj.oclc = record.oclc;
- content.oclc = record.oclc;
- content.url = 'https://www.worldcat.org/oclc/' +
record.oclc;
+ return xml2js.parseStringAsync(xml).then(function(result) {
+ if (wskeyFormat === 'dc'){
+ message = 'Unable to retrieve data from ISBN ' + citationObj.isbn;
+ try {
+ if (result.searchRetrieveResponse.records[0].record.length >
0) {
+ record =
process(result.searchRetrieveResponse.records[0].record[0].recordData[0].oclcdcs[0]);
+ // TODO: Try to get OCLC number
+ // Defaults to book
+ content.itemType = getItemType(record);
+ // dublinCore.js translator properties
+ content = translate(content, record, dc[content.itemType]);
+ // Add OCLC number to response, url, and oclc fields
+ if (record.oclc){
+ citationObj.oclc = record.oclc;
+ content.oclc = record.oclc;
+ content.url = 'https://www.worldcat.org/oclc/' +
record.oclc;
+ }
+
+ citationObj.responseCode = 200;
+ citationObj.source.push('WorldCat');
+
+ return cr;
+ } else {
+ return reject();
}
-
- citationObj.responseCode = 200;
- citationObj.source.push('WorldCat');
-
- return cr;
- } else {
+ } catch (err) {
return reject();
}
- } catch (err) {
+ }
+ if (wskeyFormat === 'openSearch'){
+ console.log(result);
+ message = 'Unable to retrieve data from search query ' +
citationObj.other;
return reject();
}
})
diff --git a/test/features/scraping/worldcat.js
b/test/features/scraping/worldcat.js
new file mode 100644
index 0000000..980facd
--- /dev/null
+++ b/test/features/scraping/worldcat.js
@@ -0,0 +1,178 @@
+
+/**
+ * Tests ISBN which uses worldcat service
+ */
+
+'use strict';
+
+
+var preq = require('preq');
+var assert = require('../../utils/assert.js');
+var server = require('../../utils/server.js');
+
+describe('ISBN tests: ', function() {
+
+ this.timeout(40000);
+
+ // Use xisbn for tests
+ describe('xisbn service: ', function() {
+
+ before(function () { return server.start({
+ xisbn:true,
+ wskey:false
+ }); });
+
+ it('valid ISBN', function() {
+ return server.query('978-0-596-51979-7').then(function(res) {
+ assert.status(res, 200);
+ assert.checkCitation(res, 'MediaWiki');
+ assert.deepEqual(!!res.body[0].oclc, true, 'Missing OCLC');
+ assert.isInArray(res.body[0].source, '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);
+ assert.deepEqual(res.body[0].edition, '1st ed.', 'Unexpected
value; expected 1st ed., got ' + res.body[0].edition);
+ assert.deepEqual(res.body[0].date, '2009-01-01', 'Unexpected
value; expected 2009-01-01, got ' + res.body[0].date);
+ assert.isInArray(res.body[0].ISBN, '9780596519797');
+ assert.deepEqual(res.body[0].itemType, 'book', 'Wrong
itemType; expected book, got ' + res.body[0].itemType);
+ });
+ });
+
+ it('valid ISBN with funky author field', function() {
+ 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].oclc, true, 'Missing OCLC');
+ assert.isInArray(res.body[0].source, '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);
+ assert.isInArray(res.body[0].ISBN, '9780439784542');
+ assert.deepEqual(res.body[0].itemType, 'book', 'Wrong
itemType; expected book, got ' + res.body[0].itemType);
+ });
+ });
+
+ it('valid DVD ISBN - type Image', function() {
+ return server.query('978-0756662967').then(function(res) {
+ assert.status(res, 200);
+ assert.checkCitation(res, 'Seashore');
+ assert.deepEqual(!!res.body[0].oclc, true, 'Missing OCLC');
+ assert.isInArray(res.body[0].source, 'WorldCat');
+ assert.deepEqual(!!res.body[0].author, true, 'Missing author');
+ assert.deepEqual(res.body[0].publisher, 'DK Pub.', 'Unexpected
value; expected DK Pub., got ' + res.body[0].publisher);
+ assert.deepEqual(res.body[0].place, 'New York', 'Unexpected
value; expected New York, got ' + res.body[0].place);
+ assert.deepEqual(res.body[0].date, '2010-01-01', 'Unexpected
value; expected 2010-01-01, got ' + res.body[0].date);
+ assert.isInArray(res.body[0].ISBN, '9780756662967');
+ assert.deepEqual(res.body[0].itemType, 'book', 'Wrong
itemType; expected book, got ' + res.body[0].itemType);
+ });
+ });
+
+ it('invalid ISBN', function() {
+ var isbn = '9780596519798';
+ return server.query(isbn, 'mediawiki', 'en')
+ .then(function(res) {
+ assert.status(res, 404);
+ }, function(err) {
+ assert.checkError(err, 404, 'Unable to retrieve data from ISBN
' + isbn,
+ 'Unexpected error message ' + err.body.Error);
+ });
+ });
+ });
+
+ // Uses worldcat search api. This requires a working wskey in your
config.yaml file. Free temporary keys available here:
+ // https://platform.worldcat.org/wskey/keys/manage
+ describe('worldcat search api: ', function() {
+ before(function () { return server.start(); });
+
+ it('valid book ISBN - type Text', function() {
+ return server.query('978-0-596-51979-7').then(function(res) {
+ assert.status(res, 200);
+ assert.checkCitation(res, 'MediaWiki');
+ assert.deepEqual(!!res.body[0].oclc, true, 'Missing OCLC');
+ assert.isInArray(res.body[0].source, 'WorldCat');
+ assert.deepEqual(res.body[0].author, [['Barrett, Daniel',
'J.']], 'Unexpected value:' + res.body[0].author);
+ assert.deepEqual(res.body[0].publisher, 'O\'Reilly',
'Unexpected value; expected O\'Reilly, got ' + res.body[0].publisher);
+ //assert.deepEqual(res.body[0].place, 'Sebastapool, Calif.',
'Unexpected value; expected Sebastapool, Calif., got ' + res.body[0].place); //
Not currently working with Worldcat Search API - not present in results
+ //assert.deepEqual(res.body[0].edition, '1st ed.', 'Unexpected
value; expected 1st ed., got ' + res.body[0].edition); // Not currently working
with Worldcat Search API - present in description tag
+ assert.deepEqual(res.body[0].date, '2009-01-01', 'Unexpected
value; expected 2009-01-01, got ' + res.body[0].date);
+ assert.isInArray(res.body[0].ISBN, '9780596519797');
+ assert.deepEqual(res.body[0].itemType, 'book', 'Wrong
itemType; expected book, got ' + res.body[0].itemType);
+ });
+ });
+
+ it('valid DVD ISBN - type Image', function() {
+ return server.query('978-0756662967').then(function(res) {
+ assert.status(res, 200);
+ assert.checkCitation(res); // Returns either 'Seashore' or
'Eyewitness DVD. Seashore.' as title
+ assert.deepEqual(!!res.body[0].oclc, true, 'Missing OCLC');
+ assert.isInArray(res.body[0].source, 'WorldCat');
+ //assert.deepEqual(res.body[0].contributor,
[['Sheen,','Martin.'],['Cohen,','Bonni.'],['Thomson,','Richard.'],['DK
Publishing,','Inc.']], 'Unexpected value:' + res.body[0].author); // only get
this sometimes
+ assert.deepEqual(res.body[0].studio, 'DK Pub', 'Unexpected
value; expected DK Pub, got ' + res.body[0].studio);
+ //assert.deepEqual(res.body[0].place, 'New York', 'Unexpected
value; expected New York, got ' + res.body[0].place);
+ //assert.deepEqual(res.body[0].date, '2010-01-01', 'Unexpected
value; expected 2010-01-01, got ' + res.body[0].date); // Not currently working
with worldcat; date is returned to us as '2010, ©1996'
+ assert.isInArray(res.body[0].ISBN, '9780756662967');
+ assert.deepEqual(res.body[0].itemType, 'videoRecording',
'Wrong itemType; expected videoRecording, got ' + res.body[0].itemType);
+ });
+ });
+
+ it('valid DVD ISBN - invalid Type', function() {
+ return server.query('9780783244396').then(function(res) {
+ assert.status(res, 200);
+ assert.checkCitation(res, 'Jaws');
+ assert.deepEqual(!!res.body[0].oclc, true, 'Missing OCLC');
+ assert.isInArray(res.body[0].source, 'WorldCat');
+ assert.deepEqual(!!res.body[0].contributor, true, 'Missing
contributor');
+ assert.deepEqual(res.body[0].studio, 'Universal', 'Unexpected
value; expected Universal, got ' + res.body[0].studio);
+ assert.deepEqual(res.body[0].date, '2000-01-01', 'Unexpected
value; expected 2000-01-01, got ' + res.body[0].date);
+ assert.isInArray(res.body[0].ISBN, '9780783244396');
+ assert.deepEqual(res.body[0].itemType, 'videoRecording',
'Wrong itemType; expected videoRecording, got ' + res.body[0].itemType);
+ });
+ });
+
+ it('valid ISBN with funky author field', function() {
+ return server.query('9780439784542').then(function(res) {
+ assert.status(res, 200);
+ assert.checkCitation(res); // Title varies, , 'Harry Potter
and the Half-Blood Prince #6.' or 'Harry Potter and the half-blood prince :
Year 6'
+ assert.deepEqual(!!res.body[0].oclc, true, 'Missing OCLC');
+ assert.isInArray(res.body[0].source, 'WorldCat');
+ //assert.deepEqual(!!res.body[0].author, true, 'Missing
author'); // Varies between true and false
+ //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);
+ assert.isInArray(res.body[0].ISBN, '9780439784542');
+ assert.deepEqual(res.body[0].itemType, 'book', 'Wrong
itemType; expected book, got ' + res.body[0].itemType);
+ });
+ });
+
+ it('invalid ISBN', function() {
+ var isbn = '9780596519798';
+ return server.query(isbn, 'mediawiki', 'en')
+ .then(function(res) {
+ assert.status(res, 404);
+ }, function(err) {
+ assert.checkError(err, 404, 'Unable to retrieve data from ISBN
' + isbn,
+ 'Unexpected error message ' + err.body.Error);
+ });
+ });
+ });
+
+});
+
+describe.only('worldcat open search tests: ', function() {
+ before(function () { return server.start(); });
+
+ it('title search', function() {
+ return server.query('mediawiki').then(function(res) {
+ assert.status(res, 200);
+ assert.checkCitation(res, 'MediaWiki');
+ assert.deepEqual(!!res.body[0].oclc, true, 'Missing OCLC');
+ assert.isInArray(res.body[0].source, 'WorldCat');
+ assert.deepEqual(res.body[0].author, [['Barrett, Daniel', 'J.']],
'Unexpected value:' + res.body[0].author);
+ assert.deepEqual(res.body[0].publisher, 'O\'Reilly', 'Unexpected
value; expected O\'Reilly, got ' + res.body[0].publisher);
+ //assert.deepEqual(res.body[0].place, 'Sebastapool, Calif.',
'Unexpected value; expected Sebastapool, Calif., got ' + res.body[0].place); //
Not currently working with Worldcat Search API - not present in results
+ //assert.deepEqual(res.body[0].edition, '1st ed.', 'Unexpected
value; expected 1st ed., got ' + res.body[0].edition); // Not currently working
with Worldcat Search API - present in description tag
+ assert.deepEqual(res.body[0].date, '2009-01-01', 'Unexpected
value; expected 2009-01-01, got ' + res.body[0].date);
+ assert.isInArray(res.body[0].ISBN, '9780596519797');
+ assert.deepEqual(res.body[0].itemType, 'book', 'Wrong itemType;
expected book, got ' + res.body[0].itemType);
+ });
+ });
+});
--
To view, visit https://gerrit.wikimedia.org/r/350558
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Icfd15e4a22a9ae5b2d25084a2476097d896f24db
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/citoid
Gerrit-Branch: master
Gerrit-Owner: Mvolz <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits