Arlolra has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/353325 )

Change subject: T115395: Mock the batch api
......................................................................

T115395: Mock the batch api

 * Enabled in the mocha http api tests, which make at least one
   preprocessor request at the moment.

Change-Id: I0383c38cffb8b9cf37b72df87f60e216938906fb
---
M tests/mocha/api.js
M tests/mockAPI.js
2 files changed, 40 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/parsoid 
refs/changes/25/353325/1

diff --git a/tests/mocha/api.js b/tests/mocha/api.js
index eb971dc..c23d2c7 100644
--- a/tests/mocha/api.js
+++ b/tests/mocha/api.js
@@ -19,6 +19,8 @@
 var optionsYaml = fs.readFileSync(optionsPath, 'utf8');
 var parsoidOptions = yaml.load(optionsYaml).services[0].conf;
 
+parsoidOptions.useBatchAPI = true;
+
 var defaultContentVersion = '1.4.0';
 
 describe('Parsoid API', function() {
diff --git a/tests/mockAPI.js b/tests/mockAPI.js
index c1e2b79..b12e1a3 100644
--- a/tests/mockAPI.js
+++ b/tests/mockAPI.js
@@ -241,6 +241,17 @@
        },
 };
 
+var preProcess = function(text) {
+       var match = text.match(/{{echo\|(.*?)}}/);
+       if (match) {
+               return { wikitext: match[1] };
+       } else if (text === '{{colours of the rainbow}}') {
+               return { wikitext: 'purple' };
+       } else {
+               return null;
+       }
+};
+
 var availableActions = {
        parse: function(body, cb) {
                var resultText;
@@ -391,16 +402,37 @@
        },
 
        expandtemplates: function(body, cb) {
-               var match = body.text.match(/{{echo\|(.*?)}}/);
-               if (match) {
-                       cb(null, { expandtemplates: { wikitext: match[1] } });
-               } else if (body.text === '{{colours of the rainbow}}') {
-                       cb(null, { expandtemplates: { wikitext: 'purple' } });
-               } else {
+               var res = preProcess(body.text);
+               if (res === null) {
                        cb(new Error('Sorry!'));
+               } else {
+                       cb(null, { expandtemplates: res });
                }
        },
 
+       'parsoid-batch': function(body, cb) {
+               var batch;
+               try {
+                       batch = JSON.parse(body.batch);
+                       console.assert(Array.isArray(batch));
+               } catch (e) {
+                       return cb(e);
+               }
+               var errs = [];
+               var results = batch.map(function(b) {
+                       var res = null;
+                       switch (b.action) {
+                               case 'preprocess':
+                                       res = preProcess(b.text);
+                                       break;
+                       }
+                       if (res === null) { errs.push(b); }
+                       return res;
+               });
+               var err = (errs.length > 0) ? new Error(JSON.stringify(errs)) : 
null;
+               cb(err, { 'parsoid-batch': results });
+       },
+
        // Return a dummy response
        templatedata: function(body, cb) {
                cb(null, {

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I0383c38cffb8b9cf37b72df87f60e216938906fb
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: Arlolra <[email protected]>

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

Reply via email to