cumulocity-cypress
Version:
Cypress commands for Cumulocity IoT
125 lines (124 loc) • 4.59 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";
declare global {
interface Response {
data?: string | any;
method?: string;
responseObj?: Partial<Cypress.Response<any>>;
requestBody?: string | any;
}
namespace Cypress {
interface Response<T> {
url?: string;
requestBody?: string | any;
method?: string;
$body?: any;
}
}
}
/**
* 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;
record: C8yPactRecord;
schemaMatcher: C8ySchemaMatcher;
strictMatching: boolean;
}>;
/**
* 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;
bearer?: (() => string) | string;
userAlias?: string;
type?: string;
}
export type C8yAuthArgs = string | C8yAuthOptions;
interface LogOptions {
consoleProps: any;
loggedInUser?: string;
logger?: {
end: () => void;
};
}
export declare function wrapFetchRequest(url: RequestInfo | URL, fetchOptions?: RequestInit, logOptions?: LogOptions): Promise<Response>;
export declare function wrapFetchResponse(response: Response, options?: {
url?: RequestInfo | URL;
fetchOptions?: IFetchOptions;
duration?: number;
logOptions?: LogOptions;
}): Promise<Response>;
/**
* Converts the given URL to a string.
* @param url The URL or RequestInfo to convert.
* @returns The URL as a string.
*/
export declare function toUrlString(url: RequestInfo | URL): string;
/**
* 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;
export declare function getAuthCookies(response: Response | Cypress.Response<any>): {
authorization?: string;
xsrfToken?: string;
} | undefined;
export declare function oauthLogin(auth: C8yAuthOptions, baseUrl?: C8yBaseUrl): Promise<C8yAuthOptions>;
export declare function getCookieValue(name: string): string | undefined;
export {};