wiremock-captain
Version:
A better way to use the WireMock simulator to test your HTTP APIs
96 lines (95 loc) • 4.07 kB
TypeScript
import { IMockedRequestResponse, Method } from './types/internalTypes';
import { IWireMockFeatures } from './types/IWireMockFeatures';
import { IWireMockRequest } from './types/IWireMockRequest';
import { IWireMockResponse } from './types/IWireMockResponse';
import { MatchingAttributes } from './types/externalTypes';
export declare class WireMock {
protected readonly baseUrl: string;
protected readonly features: IWireMockFeatures;
constructor(baseUrl: string, features?: Omit<IWireMockFeatures, 'scenario' | 'stubPriority'>);
/**
* Creates a new stub with desired request and response match
* @param request Request object for the stub mapping
* @param response AxiosResponse object for the stub mapping
* @param features Additional options to be used for creation of stub mapping
* @returns Created wiremock stub mapping. Contains `id` which is needed to delete a mapping
*/
register(request: IWireMockRequest, response: IWireMockResponse, features?: IWireMockFeatures): Promise<IMockedRequestResponse>;
/**
* Removes all the existing stubs and logs of incoming requests
*/
clearAll(): Promise<Response[]>;
/**
* Removes all the non-default mappings (not defined in backing store)
* and logs of incoming requests
*/
clearAllExceptDefault(): Promise<Response[]>;
/**
* Removes all existing stubs
*/
clearAllMappings(): Promise<Response>;
/**
* Removes log of all past incoming requests
*/
clearAllRequests(): Promise<Response>;
/**
* Deletes a stub mapping
* @param id ID of the stub to be deleted. Can be obtained when from response of `register()`
*/
deleteMapping(id: string): Promise<Response>;
/**
* Returns all the request and response mappings attached to the wiremock instance
* @returns Collection of all mappings for the wiremock instance
*/
getAllMappings(): Promise<unknown[]>;
/**
* @returns List of all requests made to the mocked instance
*/
getAllRequests(): Promise<unknown[]>;
/**
* @returns List of all scenarios in place for the mocked instance
*/
getAllScenarios(): Promise<unknown[]>;
/**
* Returns information about the mocked request and response corresponding to the `id`
* @param id Mapping ID to get the mapping info for
* @returns Single object mapping corresponding to the input `id`
*/
getMapping(id: string): Promise<unknown>;
/**
* Returns list of request(s) made to the WireMock API
* @param method Method to match the request(s) made against
* @param endpointUrl URL to get the request(s) made against
* @returns List of wiremock requests made to the endpoint with given method
*/
getRequestsForAPI(method: Method, endpointUrl: string): Promise<unknown[]>;
/**
* Returns list of unmatched request(s)
* @returns List of wiremock requests made that did not match any mapping
*/
getUnmatchedRequests(): Promise<unknown[]>;
/**
* Resets all the scenarios to the original state
*/
resetAllScenarios(): Promise<Response>;
/**
* Restores stub mappings to the defaults defined back in the backing store
*/
resetMappings(): Promise<Response>;
/**
* Finds a mapping by metadata.
* @param matchObject - The object containing metadata to match.
* @param matchType - The type of matching attributes.
* @returns The found mappings.
*/
findMappingByMetadata(matchObject: Record<string, unknown>, matchType: MatchingAttributes): Promise<unknown[]>;
/**
* Removes a mapping by metadata.
* @param matchObject - The object containing metadata to match.
* @param matchType - The type of matching attributes.
* @returns The result of the removal operation.
*/
removeMappingByMetadata(matchObject: Record<string, unknown>, matchType: MatchingAttributes): Promise<unknown>;
protected makeUrl(endpoint: string): string;
private mergeWireMockFeatures;
}