cumulocity-cypress
Version:
Cypress commands for Cumulocity IoT
72 lines (71 loc) • 3.68 kB
TypeScript
import { C8yClient } from "../c8yclient";
import { C8yPact, C8yPactID, C8yPactInfo, C8yPactRecord, C8yPactRequest, C8yPactSaveKeys } from "./c8ypact";
import { C8ySchemaGenerator } from "./schema";
import { C8yPactPreprocessor } from "./preprocessor";
import { C8yBaseUrl } from "../types";
/**
* Default implementation of C8yPact. Use C8yDefaultPact.from to create a C8yPact from
* a Cypress.Response object, a serialized pact as string or an object implementing the
* C8yPact interface. Note, objects implementing the C8yPact interface may not provide
* all required functions and properties.
*/
export declare class C8yDefaultPact implements C8yPact {
records: C8yPactRecord[];
info: C8yPactInfo;
id: C8yPactID;
protected recordIndex: number;
protected iteratorIndex: number;
protected requestIndexMap: {
[key: string]: number;
};
static strictMatching: boolean;
constructor(records: C8yPactRecord[], info: C8yPactInfo, id: C8yPactID);
/**
* Creates a C8yPact from a Cypress.Response object, a serialized pact as string
* or an object containing the pact records and info object. Throws an error if
* the input can not be converted to a C8yPact.
* @param obj The Cypress.Response, string or object to create a pact from.
* @param info The C8yPactInfo object containing additional information for the pact.
* @param client The optional C8yClient for options and auth information.
*/
static from(...args: [obj: Cypress.Response<any>, info: C8yPactInfo, client?: C8yClient] | [obj: string | C8yPact]): C8yDefaultPact;
clearRecords(): void;
appendRecord(record: C8yPactRecord, skipIfExists?: boolean): boolean;
replaceRecord(record: C8yPactRecord): boolean;
/**
* Returns the next pact record or null if no more records are available.
*/
nextRecord(): C8yPactRecord | null;
nextRecordMatchingRequest(request: Partial<Request> | {
url: string;
method: string;
}, baseUrl?: C8yBaseUrl): C8yPactRecord | null;
protected getIndexForKey(key: string): number;
protected setIndexForKey(key: string, index: number): void;
protected indexMapKey(request: Partial<Request> | C8yPactRequest, baseUrl?: C8yBaseUrl): string | undefined;
protected normalizeUrl(url: string | URL, parametersToRemove?: string[], baseUrl?: C8yBaseUrl): string;
protected matchUrls(url1: string | URL, url2: string | URL, baseUrl?: C8yBaseUrl): boolean;
protected getRequesIndex(key: string): number;
/**
* Returns the pact record for the given request or null if no record is found.
* Currently only url and method are used for matching.
* @param req The request to use for matching.
*/
getRecordsMatchingRequest(req: Partial<Request> | C8yPactRequest, baseUrl?: C8yBaseUrl): C8yPactRecord[] | null;
/**
* Returns an iterator for the pact records to iterate records using `for (const record of pact) {...}`.
*/
[Symbol.iterator](): Iterator<C8yPactRecord | null>;
}
export type C8yPactSerializeOptions = {
preprocessor?: C8yPactPreprocessor;
client?: C8yClient;
modifiedResponse?: Cypress.Response<any>;
schemaGenerator?: C8ySchemaGenerator;
loggedInUser?: string;
loggedInUserAlias?: string;
authType?: string;
baseUrl?: C8yBaseUrl;
};
export declare function toSerializablePactRecord(response: Partial<Cypress.Response<any>>, options?: C8yPactSerializeOptions): C8yPactRecord;
export declare function toPactSerializableObject(response: Partial<Cypress.Response<any>>, info: C8yPactInfo, options?: C8yPactSerializeOptions): Promise<Pick<C8yPact, C8yPactSaveKeys>>;