UNPKG

@ply-ct/ply

Version:

REST API Automated Testing

161 lines (160 loc) 5.12 kB
import { Values } from './values'; import * as flowbee from './flowbee'; import { Request } from './request'; import { Response, PlyResponse } from './response'; import { Storage } from './storage'; import { Retrieval } from './retrieval'; import { Options, PlyOptions, RunOptions } from './options'; import { Log } from './log'; import { Diff } from './compare'; import { Yaml } from './yaml'; import { Runs } from './runs/runs'; export declare type ResultStatus = 'Pending' | 'Passed' | 'Failed' | 'Errored' | 'Submitted' | 'Waiting'; export declare type ResultData = string | { [key: string]: any; } | any[]; export interface Outcome { /** * Status of test execution */ status: ResultStatus; message?: string; data?: ResultData; /** * One-based line number of first diff, relative to starting line of test */ line?: number; /** * Diff message */ diff?: string; diffs?: Diff[]; start?: number; end?: number; } export interface Result extends Outcome { /** * Request name */ name: string; /** * Request with runtime substitutions, minus Authorization header */ request?: Request; /** * Response maybe with ignore headers removed, and formatted/sorted body content (per options). * If binary media type, response body is base64 encoded. */ response?: Response; } export interface ResultOptions { subflow?: string; level: number; comment?: string; withExpected?: boolean; } export declare class PlyResult implements Result { readonly name: string; status: 'Pending' | 'Passed' | 'Failed' | 'Errored' | 'Submitted' | 'Waiting'; message?: string; line: number; diff?: string; request: Request; response: PlyResponse; graphQl?: string; constructor(name: string, request: Request, response: PlyResponse); /** * Returns the result with request/response bodies as objects (if parseable). */ getResult(options: Options): Result; merge(outcome: Outcome): void; } export declare class Verifier { private readonly name; private readonly expectedYaml; private readonly logger; constructor(name: string, expectedYaml: Yaml, logger: Log); /** * Verify expected vs actual results yaml after substituting values. * Diffs/messages always contain \n newlines. */ verify(actualYaml: Yaml, values: Values, runOptions?: RunOptions): Outcome; private diffLine; /** * Adds pre to the beginning of each line in str (except trailing newline). * Optional codeLines, start to restore comments. */ private prefix; } export declare class ResultPaths { readonly expected: Retrieval; readonly actual: Storage; readonly options: Options; readonly log: Storage; readonly runs: Runs; isFlowResult: boolean; private constructor(); /** * excluding file extension */ private static bases; /** * Figures out locations and file extensions for results. * Result file path relative to configured result location is the same as retrieval relative * to configured tests location. */ static create(options: PlyOptions, retrieval: Retrieval, suiteName?: string): Promise<ResultPaths>; /** * Figures out locations and file extensions for results. * Result file path relative to configured result location is the same as retrieval relative * to configured tests location. */ static createSync(options: PlyOptions, retrieval: Retrieval, suiteName?: string): ResultPaths; /** * Flow step result by id */ static extractById(yamlObj: any, id: string, instNum: number, indent?: number): any; /** * Newlines are always \n. */ getExpectedYaml(name?: string, instNum?: number): Promise<Yaml>; expectedExists(name?: string, instNum?: number): Promise<boolean>; /** * Newlines are always \n. Trailing \n is appended. */ getActualYaml(name?: string, instNum?: number): Yaml; responsesFromActual(): { [key: string]: Response & { source: string; }; }; flowInstanceFromActual(flowPath: string): flowbee.FlowInstance | undefined; } /** * Parses a request's response from actual results. */ export declare class ResponseParser { private readonly options; private actualYaml; private yamlLines; private actualObj; constructor(actualResult: Storage, options: Options); parse(): { [key: string]: Response & { source: string; }; }; } /** * Parses a flow instance from actual results. */ export declare class ResultFlowParser { private readonly options; private actualYaml; private yamlLines; private actualObj; constructor(actualResult: Storage, options: Options); parse(flowPath: string): flowbee.FlowInstance | undefined; getStepInstances(obj: any, offset?: number): flowbee.StepInstance[]; parseStartEnd(flowElementInstance: flowbee.StepInstance | flowbee.SubflowInstance, obj: any, offset?: number): void; }