Initial add

This commit is contained in:
Jaco Greeff
2017-11-18 08:38:18 +01:00
commit b0c7e3a8ae
49 changed files with 1594 additions and 0 deletions
+31
View File
@@ -0,0 +1,31 @@
// ISC, Copyright 2017 Jaco Greeff
const nock = require('nock');
const TEST_HTTP_URL = 'http://localhost:9944';
function mockHttp (requests) {
nock.cleanAll();
return requests.reduce((scope, request, index) => {
return scope
.post('/')
.reply(request.code || 200, (uri, body) => {
if (body.method !== request.method) {
return {
error: `Invalid method ${body.method}, expected ${request.method}`
};
}
scope.body = scope.body || {};
scope.body[request.method] = body;
return Object.assign({ id: body.id, jsonrpc: '2.0' }, request.reply || {});
});
}, nock(TEST_HTTP_URL));
}
module.exports = {
TEST_HTTP_URL,
mockHttp
};