Files
api/packages/api-provider/test/mockHttp.js
Jaco Greeff e8ccc9aa79 Move to lerna repo (#19)
* Pull api-* packages into lerna repo

* Bootstrap with hoist

* Update jest alias config

* Add api-jsonrpc

* Pull in jsonrpc

* Update badges

* Don't hoist, use workspaces

* .eslintrc to root

* Cleanups, build from root

* Shorthand commands

* Update to @polkadot/dev 0.9.1

* Update description
2017-11-28 18:03:48 +01:00

26 lines
562 B
JavaScript

// 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) => {
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
};