mirror of
https://github.com/pezkuwichain/pezkuwi-api.git
synced 2026-11-05 23:21:07 +00:00
Rebrand: polkadot → pezkuwi, substrate → bizinikiwi, kusama → dicle
This commit is contained in:
commit
d5f038faea
1383 files changed
+1088018
No files matched your search
@@ -0,0 +1,35 @@
|
||||
// Copyright 2017-2025 @pezkuwi/rpc-provider authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Mock } from './types.js';
|
||||
|
||||
import nock from 'nock';
|
||||
|
||||
interface Request {
|
||||
code?: number;
|
||||
method: string;
|
||||
reply?: Record<string, unknown>;
|
||||
}
|
||||
|
||||
interface HttpMock extends Mock {
|
||||
post: (uri: string) => {
|
||||
reply: (code: number, handler: (uri: string, body: { id: string }) => unknown) => HttpMock
|
||||
}
|
||||
}
|
||||
|
||||
export const TEST_HTTP_URL = 'http://localhost:9944';
|
||||
|
||||
export function mockHttp (requests: Request[]): Mock {
|
||||
nock.cleanAll();
|
||||
|
||||
return requests.reduce((scope: HttpMock, request: Request) =>
|
||||
scope
|
||||
.post('/')
|
||||
.reply(request.code || 200, (_uri: string, body: { id: string }) => {
|
||||
scope.body = scope.body || {};
|
||||
scope.body[request.method] = body;
|
||||
|
||||
return Object.assign({ id: body.id, jsonrpc: '2.0' }, request.reply || {}) as unknown;
|
||||
}),
|
||||
nock(TEST_HTTP_URL) as unknown as HttpMock);
|
||||
}
|
||||
Reference in new issue
Block a user