From 20223b8b01f47fba0858d854c5744fad5900b9cc Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sat, 5 Jan 2019 12:33:18 +0100 Subject: Automatic API test (#2207) * Automatic API test Easier for end-user, smarter, and the guess testing of greader authorization token was not reliable. * Travis + minor --- p/scripts/api.js | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 p/scripts/api.js (limited to 'p/scripts/api.js') diff --git a/p/scripts/api.js b/p/scripts/api.js new file mode 100644 index 000000000..841b16a6a --- /dev/null +++ b/p/scripts/api.js @@ -0,0 +1,62 @@ +"use strict"; +/* jshint esversion:6, strict:global */ + +function check(url, next) { + if (!url || !next) { + return; + } + const req = new XMLHttpRequest(); + req.open('GET', url, true); + req.setRequestHeader('Authorization', 'GoogleLogin auth=test/1'); + req.onerror = function (e) { + next('FAIL: HTTP ' + e); + }; + req.onload = function () { + if (this.status == 200) { + next(this.response); + } else { + next('FAIL: HTTP error ' + this.status + ' ' + this.statusText); + } + }; + req.send(); +} + +const jsonVars = JSON.parse(document.getElementById('jsonVars').innerHTML); + +check(jsonVars.greader + '/check/compatibility', function next(result1) { + const greaderOutput = document.getElementById('greaderOutput'); + if (result1 === 'PASS') { + greaderOutput.innerHTML = '✔️ ' + result1; + } else { + check(jsonVars.greader + '/check%2Fcompatibility', function next(result2) { + if (result2 === 'PASS') { + greaderOutput.innerHTML = '⚠️ WARN: no %2F support, so some clients will not work!'; + } else { + check('./greader.php/check/compatibility', function next(result3) { + if (result3 === 'PASS') { + greaderOutput.innerHTML = '⚠️ WARN: Probable invalid base URL in ./data/config.php'; + } else { + greaderOutput.innerHTML = '❌ ' + result1; + } + }); + } + }); + } + }); + +check(jsonVars.fever + '?api', function next(result1) { + const feverOutput = document.getElementById('feverOutput'); + try { + JSON.parse(result1); + feverOutput.innerHTML = '✔️ PASS'; + } catch (ex) { + check('./fever.php?api', function next(result2) { + try { + JSON.parse(result2); + feverOutput.innerHTML = '⚠️ WARN: Probable invalid base URL in ./data/config.php'; + } catch (ex) { + feverOutput.innerHTML = '❌ ' + result1; + } + }); + } + }); -- cgit v1.2.3