cumulocity-cypress
Version:
Cypress commands for Cumulocity IoT
147 lines (146 loc) • 5.48 kB
TypeScript
import { C8yAuthentication } from "./auth";
import { Client, IAuthentication, ICredentials, IFetchOptions, IFetchResponse, IResult, IResultList } from "@c8y/client";
import { C8yPactRecord } from "./c8ypact/c8ypact";
import { C8ySchemaMatcher } from "./c8ypact/schema";
import { C8yBaseUrl } from "./types";
/**
* C8yClientError is an error class used to throw errors related to the c8yclient command.
* It extends the built-in Error class and adds an optional originalError property.
*/
export declare class C8yClientError extends Error {
originalError?: Error;
constructor(message: string, originalError?: Error);
}
/**
* Options used to configure c8yclient command.
*/
export type C8yClientOptions = Partial<Cypress.Loggable> & Partial<Cypress.Timeoutable> & Partial<Pick<Cypress.Failable, "failOnStatusCode">> & Partial<{
auth: IAuthentication;
baseUrl: C8yBaseUrl;
client: Client;
preferBasicAuth: boolean;
skipClientAuthentication: boolean;
failOnPactValidation: boolean;
ignorePact: boolean;
schema: any;
matchSchemaAndObject: boolean;
record: C8yPactRecord;
schemaMatcher: C8ySchemaMatcher;
strictMatching: boolean;
/** Custom ID to identify this request in logs. If not provided, a unique ID will be generated. */
requestId: string;
}>;
/**
* Wrapper for Client to pass auth and options without extending Client.
* Using underscore to avoid name clashes with Client and misunderstandings reading the code.
*/
export interface C8yClient {
_auth?: C8yAuthentication;
_options?: C8yClientOptions;
_client?: Client;
}
/**
* C8yAuthOptions is used to configure the authentication for the cy.c8yclient command. It is
* an extension of the ICredentials interface from the @c8y/client package adding
* userAlias and type property.
*/
export interface C8yAuthOptions extends ICredentials {
sendImmediately?: boolean;
userAlias?: string;
type?: string;
}
export type C8yAuthArgs = string | C8yAuthOptions;
export interface C8yClientRequestContextOnRequest {
contextId: string;
url: string;
method: string;
headers?: any;
body?: any;
startTime?: number;
options?: any;
additionalInfo?: any;
}
export interface C8yClientRequestContextOnRequestEnd extends C8yClientRequestContextOnRequest {
status?: number;
error?: any;
options?: any;
fetchOptions?: any;
yielded?: any;
additionalInfo?: any;
success?: boolean;
duration?: number;
}
export interface C8yClientRequestContext {
contextId: string;
logger?: Cypress.Log;
options: C8yClientOptions;
startTime: number;
requests?: Cypress.Response<any>[];
client?: C8yClient;
savePact: boolean;
ignorePact: boolean;
}
export interface C8yClientLogOptions {
consoleProps?: any;
loggedInUser?: string;
contextId?: string;
startTime?: number;
options?: C8yClientOptions;
onRequestStart?: (requestDetails: C8yClientRequestContextOnRequest) => void;
onRequestEnd?: (responseDetails: C8yClientRequestContextOnRequestEnd) => void;
}
export declare function wrapFetchRequest(url: RequestInfo | URL, fetchOptions?: RequestInit, logOptions?: C8yClientLogOptions): Promise<Response>;
export declare function wrapFetchResponse(response: Response, options?: {
url?: RequestInfo | URL;
fetchOptions?: IFetchOptions;
duration?: number;
logOptions?: C8yClientLogOptions;
}): Promise<Response>;
/**
* Converts the given object to a Cypress.Response.
* @param obj The object to convert.
* @param duration The duration of the request.
* @param fetchOptions The fetch options used for the request.
* @param url The URL of the request.
* @param schema The schema of the response.
*/
export declare function toCypressResponse(obj: IFetchResponse | IResult<any> | IResultList<any> | C8yPactRecord | Partial<Response>, duration?: number, fetchOptions?: IFetchOptions, url?: RequestInfo | URL, schema?: any): Cypress.Response<any> | undefined;
/**
* Converts a Cypress.Response or C8yPactRecord to a window.Response. If
* the given object is not a Cypress.Response or C8yPactRecord, undefined
* is returned.
* @param obj The object to check.
*/
export declare function toWindowFetchResponse(obj: Cypress.Response<any> | C8yPactRecord): Response | undefined;
/**
* Converts the given headers to a window.Headers object.
* @param headers The headers object to convert.
*/
export declare function toResponseHeaders(headers: {
[key: string]: string | string[];
}): Headers;
/**
* Checks if the given object is a window.Response.
* @param obj The object to check.
*/
export declare function isWindowFetchResponse(obj: any): obj is Response;
/**
* Checks if the given object is an IResult.
* @param obj The object to check.
*/
export declare function isIResult(obj: any): obj is IResult<any>;
/**
* Checks if the given object is a CypressError.
* @param error The object to check.
* @returns True if the object is a CypressError, false otherwise.
*/
export declare function isCypressError(error: any): boolean;
/**
* Checks if the given object is a C8yClientError.
* @param error The object to check.
* @returns True if the object is a C8yClientError, false otherwise.
*/
export declare function isC8yClientError(error: any): boolean;
export declare function throwC8yClientError(error: Error, url?: RequestInfo | URL | undefined, logOptions?: C8yClientLogOptions & {
method?: string;
}): never;