syntropylog
Version:
An instance manager with observability for Node.js applications
48 lines (47 loc) • 1.67 kB
TypeScript
/**
* MockHttpClient - Framework Agnostic Mock
*
* This mock provides a testing-agnostic version of IHttpClientAdapter
* that can be used with both Vitest and Jest without conflicts.
*/
export interface AdapterHttpRequest {
url: string;
method: string;
headers: Record<string, any>;
body?: any;
timeout?: number;
}
export interface AdapterHttpResponse<T = any> {
statusCode: number;
data: T;
headers: Record<string, any>;
}
export interface AdapterHttpError extends Error {
request: AdapterHttpRequest;
isAdapterError: boolean;
}
export interface IHttpClientAdapter {
request(request: AdapterHttpRequest): Promise<AdapterHttpResponse<any>>;
get(url: string, headers?: Record<string, any>): Promise<AdapterHttpResponse<any>>;
post(url: string, body?: any, headers?: Record<string, any>): Promise<AdapterHttpResponse<any>>;
put(url: string, body?: any, headers?: Record<string, any>): Promise<AdapterHttpResponse<any>>;
delete(url: string, headers?: Record<string, any>): Promise<AdapterHttpResponse<any>>;
patch(url: string, body?: any, headers?: Record<string, any>): Promise<AdapterHttpResponse<any>>;
}
export declare class MockHttpClient implements IHttpClientAdapter {
private spyFn;
private timeouts;
readonly request: any;
readonly get: any;
readonly post: any;
readonly put: any;
readonly delete: any;
readonly patch: any;
readonly setResponse: any;
readonly setError: any;
readonly setTimeout: any;
readonly reset: any;
constructor(spyFn?: (implementation?: any) => any);
private updateMethodImplementations;
private createMock;
}