UNPKG

@pact-foundation/pact

Version:
130 lines (129 loc) 5.96 kB
import type { JsonMap } from '../../common/jsonTypes'; import type { Matcher, Path, Rules, SpecificationVersion, StatusCodeMatcher, TemplateHeaders, TemplateQuery, V3MockServer, V3ProviderState, V3Request, V3Response } from '../../v3'; export type V4ProviderState = V3ProviderState; export type V4MockServer = V3MockServer; export type V4Request = V3Request; export type V4Response = V3Response; export interface PactV4Options { /** * Directory to write the pact file to */ dir?: string; /** * Consumer name */ consumer: string; /** * Provider name */ provider: string; /** * Port to run the mock server on. Defaults to a random port */ port?: number; /** * Specification version to use. Defaults to V4 */ spec?: SpecificationVersion; /** * Specification version to use */ logLevel?: 'trace' | 'debug' | 'info' | 'warn' | 'error'; /** * Flag to identify if HTTP or HTTPs over TLS should be used (default false, HTTP) */ tls?: boolean; /** * The host to run the mock service, defaults to 127.0.0.1 */ host?: string; /** * If the mock server should handle CORS pre-flight requests. Defaults to true */ cors?: boolean; } export type TemplateHeaderArrayValue = string[] | Matcher<string>[]; export type Comment = string; export type CustomComment = { key: string; value: string; }; export interface V4UnconfiguredInteraction { given(state: string, parameters?: JsonMap): V4UnconfiguredInteraction; uponReceiving(description: string): V4UnconfiguredInteraction; pending(pending?: boolean): V4UnconfiguredInteraction; comment(comment: Comment | CustomComment): V4UnconfiguredInteraction; testName(name: string): V4UnconfiguredInteraction; reference(group: string, name: string, value: string): V4UnconfiguredInteraction; withCompleteRequest(request: V4Request): V4InteractionWithCompleteRequest; withRequest(method: string, path: Path, builder?: V4RequestBuilderFunc): V4InteractionWithRequest; usingPlugin(config: PluginConfig): V4InteractionWithPlugin; } export interface V4InteractionWithCompleteRequest { withCompleteResponse(response: V4Response): V4InteractionWithResponse; } export interface V4InteractionWithRequest { willRespondWith(status: number | StatusCodeMatcher<number>, builder?: V4ResponseBuilderFunc): V4InteractionWithResponse; } export type V4RequestBuilderFunc = (builder: V4RequestBuilder) => void; export interface V4RequestBuilder { query(query: TemplateQuery): V4RequestBuilder; headers(headers: TemplateHeaders): V4RequestBuilder; jsonBody(body: unknown): V4RequestBuilder; xmlBody(body: unknown): V4RequestBuilder; binaryFile(contentType: string, file: string): V4RequestBuilder; multipartBody(contentType: string, filename: string, mimePartName: string, boundary?: string): V4RequestBuilder; matchingRules(rules: Rules): V4RequestBuilder; body(contentType: string, body: Buffer): V4RequestBuilder; } export interface V4ResponseBuilder { headers(headers: TemplateHeaders): V4ResponseBuilder; jsonBody(body: unknown): V4ResponseBuilder; xmlBody(body: unknown): V4ResponseBuilder; binaryFile(contentType: string, file: string): V4ResponseBuilder; multipartBody(contentType: string, filename: string, mimePartName: string, boundary?: string): V4ResponseBuilder; matchingRules(rules: Rules): V4ResponseBuilder; body(contentType: string, body: Buffer): V4ResponseBuilder; } export type V4ResponseBuilderFunc = (builder: V4ResponseBuilder) => void; export interface V4InteractionWithResponse { executeTest<T>(testFn: (mockServer: V4MockServer) => Promise<T>): Promise<T | undefined>; } export type V4PluginRequestBuilderFunc = (builder: V4RequestWithPluginBuilder) => void; export type V4PluginResponseBuilderFunc = (builder: V4ResponseWithPluginBuilder) => void; export interface PluginConfig { plugin: string; version: string; } export interface V4InteractionWithPlugin { usingPlugin(config: PluginConfig): V4InteractionWithPlugin; withRequest(method: string, path: Path, builder?: V4PluginRequestBuilderFunc): V4InteractionWithPluginRequest; } export interface V4InteractionWithPluginRequest { willRespondWith(status: number | StatusCodeMatcher<number>, builder?: V4PluginResponseBuilderFunc): V4InteractionWithPluginResponse; } export interface V4RequestWithPluginBuilder { query(query: TemplateQuery): V4RequestWithPluginBuilder; headers(headers: TemplateHeaders): V4RequestWithPluginBuilder; jsonBody(body: unknown): V4RequestWithPluginBuilder; xmlBody(body: unknown): V4RequestWithPluginBuilder; binaryFile(contentType: string, file: string): V4RequestWithPluginBuilder; multipartBody(contentType: string, filename: string, mimePartName: string, boundary?: string): V4RequestWithPluginBuilder; body(contentType: string, body: Buffer): V4RequestWithPluginBuilder; matchingRules(rules: Rules): V4RequestWithPluginBuilder; pluginContents(contentType: string, contents: string): V4RequestWithPluginBuilder; } export interface V4ResponseWithPluginBuilder { headers(headers: TemplateHeaders): V4ResponseBuilder; jsonBody(body: unknown): V4ResponseBuilder; xmlBody(body: unknown): V4ResponseBuilder; binaryFile(contentType: string, file: string): V4ResponseBuilder; multipartBody(contentType: string, filename: string, mimePartName: string, boundary?: string): V4ResponseBuilder; matchingRules(rules: Rules): V4ResponseBuilder; body(contentType: string, body: Buffer): V4ResponseBuilder; pluginContents(contentType: string, contents: string): V4ResponseBuilder; } export interface V4InteractionWithPluginResponse { executeTest<T>(testFn: (mockServer: V4MockServer) => Promise<T>): Promise<T | undefined>; } export type TestFunction<T> = (mockServer: V4MockServer) => Promise<T>;