@pact-foundation/pact
Version:
Pact for all things Javascript
64 lines (63 loc) • 3.54 kB
TypeScript
import type { JsonMap } from '../common/jsonTypes';
import { type PactV3Options, type Rules, type V3Interaction, type V3MockServer, type V3Request, type V3Response } from './types';
export declare class PactV3 {
private opts;
private states;
private pact;
private interaction;
constructor(opts: PactV3Options);
addInteraction(interaction: V3Interaction): PactV3;
given(providerState: string, parameters?: JsonMap): PactV3;
uponReceiving(description: string): PactV3;
withRequest(req: V3Request): PactV3;
withRequestBinaryFile(req: V3Request, contentType: string, file: string): PactV3;
/**
* Applies matching rules to the consumer request.
* Matching rules allow you to define flexible matching criteria for request attributes
* beyond exact equality (e.g., regex patterns, type matching, number ranges).
*
* @param req - The request configuration (method, path, headers, etc.)
* @param rules - The matching rules.
* @returns The PactV3 instance for method chaining
*/
withRequestMatchingRules(req: V3Request, rules: Rules): PactV3;
/**
* Applies matching rules to the provider response.
* Matching rules allow you to define flexible matching criteria for response attributes
* beyond exact equality (e.g., regex patterns, type matching, number ranges).
*
* @param req - The request configuration (method, path, headers, etc.)
* @param rules - The matching rules.
* @returns The PactV3 instance for method chaining
*/
withResponseMatchingRules(req: V3Request, rules: Rules): PactV3;
/**
* Sets up the expected consumer request with multipart file upload data.
* This is useful for testing APIs that accept multipart/form-data uploads.
*
* @param req - The request configuration (method, path, headers, etc.)
* @param contentType - The content type of the multipart body (e.g., 'multipart/form-data')
* @param file - Path to the file containing the multipart body content
* @param mimePartName - The name of the mime part in the multipart body
* @param boundary - Optional boundary string for the multipart content. If not provided, will be passed as undefined.
* @returns The PactV3 instance for method chaining
*/
withRequestMultipartFileUpload(req: V3Request, contentType: string, file: string, mimePartName: string, boundary?: string): PactV3;
willRespondWith(res: V3Response): PactV3;
withResponseBinaryFile(res: V3Response, contentType: string, file: string): PactV3;
/**
* Sets up the expected provider response with multipart file upload data.
* This is useful for testing APIs that respond with multipart/form-data content.
*
* @param res - The response configuration (status, headers, etc.)
* @param contentType - The content type of the multipart body (e.g., 'multipart/form-data')
* @param file - Path to the file containing the multipart body content
* @param mimePartName - The name of the mime part in the multipart body
* @param boundary - Optional boundary string for the multipart content. If not provided, will be passed as undefined.
* @returns The PactV3 instance for method chaining
*/
withResponseMultipartFileUpload(res: V3Response, contentType: string, file: string, mimePartName: string, boundary?: string): PactV3;
executeTest<T>(testFn: (mockServer: V3MockServer) => Promise<T>): Promise<T | undefined>;
private cleanup;
private setup;
}