Mobrovac has submitted this change and it was merged.

Change subject: Fix acceptLanguage commit a30d6be
......................................................................


Fix acceptLanguage commit a30d6be

* Fixed errors to CitoidService
requestFromDOI method.

* Added test for requestFromDOI
'doi'

* Fixed test from acceptLanguage commit
'German Twitter' which checked for
incorrect responseCode

* Throw callback errors in all tests

* Check error in test 520 (now test
ENOTFOUND) and throw if the error is not
the expected error (getaddrinfo ENOTFOUND)

* Add test 404 for cases where a 520 error
is expected but no error should be thrown
(for when there is a resource at the server
but the HTTP response is 404).

* Increase timeout default for mocha
since the 'doi' test takes longer
than the previous timeout length.

Change-Id: I93f8c699e7f58375e4fa8dd7c48dd721969e3659
---
M Gruntfile.js
M lib/CitoidService.js
M test/index.js
3 files changed, 74 insertions(+), 14 deletions(-)

Approvals:
  Mobrovac: Looks good to me, approved



diff --git a/Gruntfile.js b/Gruntfile.js
index 8c04814..7178f57 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -22,7 +22,7 @@
                simplemocha: {
                        options: {
                                globals: ['describe', 'its'],
-                               timeout: 3000,
+                               timeout: 20000,
                                ignoreLeaks: false,
                                ui: 'bdd',
                                reporter: 'tap'
@@ -33,7 +33,7 @@
 
        // Default task.
        grunt.registerTask('test', ['jshint:all']);
-       grunt.registerTask('withzotero', ['simplemocha']);
+       grunt.registerTask('all', ['jshint:all', 'simplemocha']);
        grunt.registerTask('default', 'test');
 
 };
diff --git a/lib/CitoidService.js b/lib/CitoidService.js
index e5d2f03..7550f5a 100644
--- a/lib/CitoidService.js
+++ b/lib/CitoidService.js
@@ -114,8 +114,9 @@
  */
 CitoidService.prototype.requestFromDOI = function (opts, callback){
        var doiLink = 'http://dx.doi.org/'+ opts.search;
+       opts.search = doiLink;
        // TODO: optimise this (can skip some steps in requestFromURL)
-       this.requestFromURL(doiLink, opts.format, callback);
+       this.requestFromURL(opts, callback);
 };
 
 /**
diff --git a/test/index.js b/test/index.js
index 8a5b414..97366ac 100644
--- a/test/index.js
+++ b/test/index.js
@@ -61,24 +61,31 @@
                                throw new Error('Missing itemType');
                        }
                        done();
-                       // TODO: Match retrieved citation to expected citation
                });
        });
 });
 
-describe('520', function() {
+describe('ENOTFOUND', function() {
 
-       var opts = {
-               search : 'example./com',
+       var url = 'example./com',
+               opts = {
+               search : url,
                format : 'mediawiki',
                acceptLanguage : 'en'
-       },
+               },
                expectedTitle = 'http://example./com';
 
-       it('should return 520 error and citation', function(done) {
+       it('should return a ENOTFOUND error, a 520 responseCode, and citation', 
function(done) {
                citoidService.request(opts, function(error, responseCode, 
citation){
+                       if (!error) {
+                               throw new Error('No error');
+                       }
+                       // Throw errors except the expected error, ENOTFOUND
+                       if (error.message !== 'getaddrinfo ENOTFOUND'){
+                               throw error;
+                       }
                        if (responseCode !== 520){
-                               throw new Error('Should throw 520: Response 
code is' + responseCode);
+                               throw new Error('Should throw 520: Response 
code is ' + responseCode);
                        }
                        if (!citation) {throw new Error ('Empty body');}
                        if (citation[0].title !== expectedTitle){
@@ -88,11 +95,39 @@
                        if (!citation[0].itemType){
                                throw new Error('Missing itemType');
                        }
-                       // TODO: Match retrieved citation to expected citation
                        done();
                });
        });
 });
+
+describe('404', function() {
+
+       var url = 'http://example.com/thisurldoesntexist',
+               opts = {
+               search : url,
+               format : 'mediawiki',
+               acceptLanguage : 'en'
+               },
+               expectedTitle = url;
+
+       it('should return a 520 responseCode and citation', function(done) {
+               citoidService.request(opts, function(error, responseCode, 
citation){
+                       if (responseCode !== 520){
+                               throw new Error('Should throw 520: 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('German twitter', function() {
 
@@ -105,9 +140,9 @@
 
        it('should return the citation for twitter in German', function(done) {
                citoidService.request(opts, function(error, responseCode, 
citation){
-                       if (responseCode !== 520){
-                               throw new Error('Should throw 520: Response 
code is' +
-                                       responseCode);
+                       if (error) {throw error;}
+                       if (responseCode !== 200){
+                               throw new Error('Should respond 200: Response 
code is ' + responseCode);
                        }
                        if (!citation) {throw new Error ('Empty body');}
                        if (citation[0].title !== expectedTitle){
@@ -118,3 +153,27 @@
                });
        });
 });
+
+describe('doi', function() {
+
+       var opts = {
+               search : 'doi: 10.1371/journal.pcbi.1002947',
+               format : 'mediawiki',
+               acceptLanguage : 'en'
+               };
+
+       it('should use return citation from doi', function(done) {
+               citoidService.request(opts, function(error, responseCode, 
citation){
+                       if (error) {throw error;}
+                       if (responseCode !== 200){
+                               throw new Error('Should respond 200: Response 
code is ' + responseCode);
+                       }
+                       if (!citation) {throw new Error ('Empty body');}
+                       if (citation[0].pages !== 'e1002947'){
+                               throw new Error('Expected pages value should 
be: e1002947; Got: '
+                                       + citation[0].pages);
+                       }
+                       done();
+               });
+       });
+});
\ No newline at end of file

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I93f8c699e7f58375e4fa8dd7c48dd721969e3659
Gerrit-PatchSet: 14
Gerrit-Project: mediawiki/services/citoid
Gerrit-Branch: master
Gerrit-Owner: Mvolz <mv...@wikimedia.org>
Gerrit-Reviewer: Catrope <roan.katt...@gmail.com>
Gerrit-Reviewer: Mobrovac <mobro...@wikimedia.org>
Gerrit-Reviewer: Mvolz <mv...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to