Files
api/packages/rpc-provider/test/mockHttp.ts
T
Jaco Greeff 47fc4a2b3c Bump deps w/ eslint (#2302)
* Bump deps w/ eslint

* Additional cleanups

* Additional

* @polkadot/types done

* Additional

* @polkadot/typegen done

* Additional

* @polkadot/rpc-core done

* Additional

* Additional

* Additional

* docs

* @polkadot/api-derive done

* @polkadot/api done

* @polkadot/api-contracts done

* Update tests
2020-05-24 09:24:45 +02:00

30 lines
783 B
TypeScript

// Copyright 2017-2020 @polkadot/rpc-provider authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
/* eslint-disable */
import nock from 'nock';
const TEST_HTTP_URL = 'http://localhost:9944';
function mockHttp (requests: any[]): any {
nock.cleanAll();
return requests.reduce((scope, request: any): nock.Scope => {
return scope
.post('/')
.reply(request.code || 200, (uri: string, body: { id: string }): any => {
scope.body = scope.body || {};
scope.body[request.method] = body;
return Object.assign({ id: body.id, jsonrpc: '2.0' }, request.reply || {});
});
}, nock(TEST_HTTP_URL));
}
export {
TEST_HTTP_URL,
mockHttp
};