-
Notifications
You must be signed in to change notification settings - Fork 0
/
checker.js
42 lines (37 loc) · 1.16 KB
/
checker.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
const fetch = require('node-fetch')
querystring = require('querystring');
function check(url, invocationParameters, expectedResultData, expectedResultStatus) {
const checkResult = {
urlChecked: null,
resultData: null,
resultStatus: null,
statusTestPassed: null,
resultDataAsExpected: null
}
url = url + "?" + querystring.stringify(invocationParameters);;
var status = null;
return fetch(url)
.then(res => {
status = res.status;
return res.json();
})
.then(json => {
const checkResult = {
urlChecked: url,
resultData: json,
resultStatus: status,
statusTestPassed: status == expectedResultStatus,
resultDataAsExpected: compareResults(expectedResultData, json)
};
return checkResult;
});
}
function compareResults(expected, actual) {
if (!expected) return true //always ok if there are no expectations
if (!actual) return false
for (let e of Object.keys(expected)) {
if (actual[e]===undefined || expected[e]!=actual[e] ) return false
}
return true
}
module.exports = check