-
Notifications
You must be signed in to change notification settings - Fork 34
/
mockServerClient.d.ts
89 lines (63 loc) · 3.46 KB
/
mockServerClient.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
* mockserver
* http://mock-server.com
*
* Original definitions by: David Tanner <https://github.com/DavidTanner>
*
* Copyright (c) 2014 James Bloom
* Licensed under the Apache License, Version 2.0
*/
import {Expectation, ExpectationId, HttpRequest, HttpRequestAndHttpResponse, HttpResponse, KeyToMultiValue, OpenAPIExpectation, RequestDefinition, Times, TimeToLive,} from './mockServer';
export type Host = string;
export type Port = number;
export type ContextPath = string;
export type TLS = boolean;
export type CaCertPemFilePath = string;
// Retains backwards compatability.
export type KeysToMultiValues = KeyToMultiValue;
export type ClearType = 'EXPECTATIONS' | 'LOG' | 'ALL';
export interface SuccessFullRequest {
statusCode: number;
body: string;
}
export type RequestResponse = SuccessFullRequest | string;
export type PathOrRequestDefinition = string | Expectation | RequestDefinition | undefined | null;
export interface MockServerClient {
openAPIExpectation(expectation: OpenAPIExpectation): Promise<RequestResponse>;
mockAnyResponse(expectation: Expectation | Expectation[]): Promise<RequestResponse>;
mockWithCallback(requestMatcher: RequestDefinition, requestHandler: (request: HttpRequest) => HttpResponse, times?: Times | number, priority?: number, timeToLive?: TimeToLive, id?: string): Promise<RequestResponse>;
mockSimpleResponse<T = any>(path: string, responseBody: T, statusCode?: number): Promise<RequestResponse>;
setDefaultHeaders(responseHeaders: KeysToMultiValues, requestHeaders: KeysToMultiValues): MockServerClient;
verify(matcher: RequestDefinition, atLeast?: number, atMost?: number): Promise<void | string>;
verifyById(expectationId: ExpectationId, atLeast?: number, atMost?: number): Promise<void | string>;
verifySequence(...matchers: RequestDefinition[]): Promise<void | string>;
verifySequenceById(...expectationIds: ExpectationId[]): Promise<void | string>;
reset(): Promise<RequestResponse>;
clear(pathOrRequestDefinition: PathOrRequestDefinition, type: ClearType): Promise<RequestResponse>;
clearById(expectationId: ExpectationId, type: ClearType): Promise<RequestResponse>;
bind(ports: Port[]): Promise<RequestResponse>;
retrieveRecordedRequests(pathOrRequestDefinition: PathOrRequestDefinition): Promise<HttpResponse[]>;
retrieveRecordedRequestsAndResponses(pathOrRequestDefinition: PathOrRequestDefinition): Promise<HttpRequestAndHttpResponse[]>;
retrieveActiveExpectations(pathOrRequestDefinition: PathOrRequestDefinition): Promise<Expectation[]>;
retrieveRecordedExpectations(pathOrRequestDefinition: PathOrRequestDefinition): Promise<Expectation[]>;
retrieveLogMessages(pathOrRequestDefinition: PathOrRequestDefinition): Promise<string[]>;
}
/**
* Start the client communicating at the specified host and port
* for example:
*
* var client = mockServerClient("localhost", 1080);
*
* @param host {string} the host for the server to communicate with
* @param port {number} the port for the server to communicate with
* @param contextPath {string} the context path if server was deployed as a war
* @param tls {boolean} enable TLS (i.e. HTTPS) for communication to server
* @param caCertPemFilePath {string} provide custom CA Certificate (defaults to MockServer CA Certificate)
*/
export declare function mockServerClient(
host: Host,
port: Port,
contextPath?: ContextPath,
tls?: TLS,
caCertPemFilePath?: CaCertPemFilePath
): MockServerClient;