export type RestMethod = 'POST' | 'GET' | 'PATCH' | 'DELETE' export type TestFn = (env: TestEnvExtended) => MaybePromise export type TestType = ExpectedType | TestFn type TestEnvExtended = TestEnv & { [k: string]: any } type Statuses = 200 | 400 | 401 | 402 | 403 | 404 | 409 | 422 | 429 | 500 | 503 type HttpHeaders = { Accept?: string 'Content-Type'?: string [k: string]: string } interface Test2, RestTestConfigType extends RestTestConfig> { /** d stands for description and is meant to describe the action / route in the most readable format: d: [403, 'userA', 'create a transaction with more that the maximum amount'] */ d?: [Statuses, TestUserNames | ConnexionInfos | 'public' | 'system', string] | [TestUserNames | ConnexionInfos | 'public' | 'system', string], // TODO route, main and svc cannot be used at the same time, so they need to be exclusively typoed route?: TestType // , main?: any, svc?: any main?: TestFn // , route?: any, svc?: any svc?: TestFn // , route?: any, main?: any method?: TestType headers?: TestType as?: TestType apiKey?: TestType auth?: TestType status?: TestType params?: TestType[]> body?: TestType, /** expected status: 200 OR [404, 403] if multiple status could be expected */ doc?: string /** Display a warning message when running the test, can be useful to display 'Should be refactored' like warnings' */ warning?: string /** Display a message info when running the test, can be useful to display '' like info */ info?: string /** Expected error message */ errorMessage?: TestType before?: TestFn after?: ((env: TestEnvExtended, reponse: any) => void) | ((env: TestEnvExtended, reponse: any) => Promise) /** Determine if the test shall run or not depending on env, useful if you want to disable test for some iterations */ shallRun?: TestType /** This test will run in parallel of the other ones, so the flow will continue while this test is finishing */ runInParallel?: TestType /** match servers props in restTestConfig */ server?: keyof RestTestConfigType['servers'] /** will replace config.serverBaseUrl */ serverUrl?: TestType /** wait a predefined amount of seconds before running that test */ waitSecBefore?: number /** wait a predefined amount of seconds after running that test */ waitSecAfter?: number /** Will display a message in case of error */ onErrorMsg?: string | GenericFunction } // TODO clean that as it's needed for module extension export interface Test, RestTestConfigType extends RestTestConfig> extends Test2 { } export type TestItem = any, RestTestConfigType extends RestTestConfig = any> = (TestElement | TestFlow) export type TestFlowRaw = any, RestTestConfigType extends RestTestConfig = any> = { name?: string defaults?: TestType>> /** The lesser the better priority */ priority?: number /** This test will run even if a filter is passed or solo option is active on one test */ mandatory?: boolean /** if active, only this test flow will run and the mandatory ones. Remove this when commiting */ solo?: boolean // TODO dependsOn setting disable?: true disableTemporarly?: `${number}${number}${number}${number}${number}${number}${number}${number}` items: TestItem[] /** This is meant to be played before reloading a test flow when a user click continue or * replayLast when a previous test has failed */ beforeReloadAll?: TestElement[] } export type TestFlow = any, RestTestConfigType extends RestTestConfig = any> = TestFlowRaw | (() => MaybePromise>) export type TestFunction = (env: RestTestConfigType['env']) => void export type TestElement, RestTestConfigType extends RestTestConfig> = Test | TestFn | TestFlow export type TestEnvBase = { users: Record } & Record export interface RestTestConfig< ApiKeys extends string = any, TestEnv extends TestEnvBase = any, TestUserNames extends string = any, ConnexionInfos extends Record = any, ApiKeysType extends Record = any > { // TODO document jsdoc displayIntroTimeout: number mode: 'jsonRpc' | 'rest' disableSolo?: boolean apiKeys: Record servers: { default: string // should be present, main server [serverNameShortcut: string]: string } env: ObjectGeneric startAtTestNb?: number afterTest?(testNb: number, env: ObjectGeneric) onError?(actualScenarioNb: number, env: ObjectGeneric) filter?: string isReload?: boolean restTestState?: Record /** trigerred before the run */ onBeforeAllTests?(conf: { isReload: boolean env: TestEnv }): any /** triggered BEFORE every tests */ onBeforeTest?(conf: { env: TestEnv, as?: TestUserNames | ConnexionInfos, apiKey?: ApiKeys, headers: Record }): any /** triggered AFTER every tests */ onAfterTest?(conf: { env: TestEnv, as?: TestUserNames | ConnexionInfos, apiKey?: ApiKeys, headers: Record }): any }