cumulocity-cypress
Version:
Cypress commands for Cumulocity IoT
123 lines (122 loc) • 4.83 kB
TypeScript
import { C8ySchemaMatcher } from "./schema";
/**
* Matcher for C8yPactRecord objects. Use C8yPactMatcher to match any two
* records. Depending on the matcher implementation an Error will be thrown
* or boolean is returned.
*/
export interface C8yPactMatcher {
/**
* Matches objectToMatch against objectPact. Returns false if objectToMatch
* does not match objectPact or throws an error with details on failing match.
*
* @param obj1 Object to match.
* @param obj2 Pact to match obj1 against.
* @param {C8yPactMatcherOptions} options The C8yPactMatcherOptions to use for matching.
*/
match: (objectToMatch: any, objectPact: any, options?: C8yPactMatcherOptions) => boolean;
}
/**
* Error thrown when a C8yPactMatcher fails to match two objects.
* Contains the actual and expected values, the key that failed to match and
* the key path of the property that failed to match.
* The key path is a string representation of the path to the property that failed to match.
* For example: "body > id" for a property "id" in the "body" object.
* This error is used to provide detailed information about the match failure.
*/
export declare class C8yPactMatchError extends Error {
actual: any;
expected: any;
key?: string;
keyPath?: string;
schema?: any;
constructor(message: string, options: {
actual: any;
expected: any;
key?: string;
keyPath?: string;
schema?: any;
});
}
export interface C8yPactMatcherOptions {
strictMatching?: boolean;
matchSchemaAndObject?: boolean;
loggerProps?: {
[key: string]: any;
};
schemaMatcher?: C8ySchemaMatcher;
parents?: (string | number)[];
ignoreCase?: boolean;
ignorePrimitiveArrayOrder?: boolean;
requestId?: string;
}
/**
* Default implementation of C8yPactMatcher to match C8yPactRecord objects. Pacts
* are matched by comparing the properties of the objects using property matchers.
* If no property matcher is configured for a property, the property will be matched
* by equality. Disable Cypress.c8ypact.config.strictMatching to ignore properties that are
* missing in matched objects. In case objects do not match an C8yPactError is thrown.
*/
export declare class C8yDefaultPactMatcher implements C8yPactMatcher {
propertyMatchers: {
[key: string]: C8yPactMatcher;
};
static schemaMatcher: C8ySchemaMatcher;
static options?: C8yPactMatcherOptions;
options?: C8yPactMatcherOptions;
/**
* Standard JSON Schema keywords that start with $ but are not schema matcher keys.
* These should be treated as regular object properties.
* @see https://json-schema.org/understanding-json-schema/reference
*/
private static readonly JSON_SCHEMA_KEYWORDS;
constructor(propertyMatchers?: {
[key: string]: C8yPactMatcher;
}, options?: C8yPactMatcherOptions);
match(obj1: any, obj2: any, options?: C8yPactMatcherOptions): boolean;
/**
* Check if a key is a schema matcher key (starts with $ but is not a standard JSON Schema keyword)
*/
private isSchemaMatcherKey;
private isKeyPathInObject;
/**
* Returns the property matcher for the given property name.
* @param key The property name to get the matcher for.
* @param ignoreCase Whether to ignore the case of the property name.
*/
getPropertyMatcher(key: string, ignoreCase?: boolean): any;
/**
* Adds a new property matcher for the given property name.
*/
addPropertyMatcher(propertyName: string, matcher: C8yPactMatcher): void;
/**
* Removes the property matcher for the given property name.
*/
removePropertyMatcher(propertyName: string): void;
}
/**
* Extends C8yDefaultPactMatcher with default property matchers for Cumulocity
* response bodies. It has rules configured at least for the following properties:
* id, statistics, lastUpdated, creationTime, next, self, password, owner, tenantId
* and lastPasswordChange. It is registered for the properties body and requestBody.
*/
export declare class C8yPactBodyMatcher extends C8yDefaultPactMatcher {
constructor(propertyMatchers?: {});
}
export declare class C8yIdentifierMatcher implements C8yPactMatcher {
match(obj1: any, obj2: any): boolean;
}
export declare class C8yNumberMatcher implements C8yPactMatcher {
match(obj1: any, obj2: any): boolean;
}
export declare class C8yStringMatcher implements C8yPactMatcher {
match(obj1: any, obj2: any): boolean;
}
export declare class C8yIgnoreMatcher implements C8yPactMatcher {
match(): boolean;
}
export declare class C8ySameTypeMatcher implements C8yPactMatcher {
match(obj1: any, obj2: any): boolean;
}
export declare class C8yISODateStringMatcher {
match(obj1: any, obj2: any): boolean;
}