import { GDapiKey } from '../plugins/index.js'; 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 GreenDotApiTestsConfig> { /** 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]; route?: TestType; main?: TestFn; svc?: TestFn; 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 suite 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; } export interface Test, RestTestConfigType extends GreenDotApiTestsConfig> extends Test2 { } export type TestItem = any, RestTestConfigType extends GreenDotApiTestsConfig = any> = (TestElement | TestSuite); export type TestSuiteRaw = any, RestTestConfigType extends GreenDotApiTestsConfig = any> = { name?: string; defaults?: TestType>>; /** The lower, the prior. From 0 to 100 */ 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 suite will run and the mandatory ones. Remove this when commiting */ solo?: boolean; disable?: true; disableTemporarly?: `${number}${number}${number}${number}${number}${number}${number}${number}`; items: TestItem[]; /** This is meant to be played before reloading a test suite when a user click continue or * replayLast when a previous test has failed */ beforeReloadAll?: TestElement[]; }; export type TestSuite = any, RestTestConfigType extends GreenDotApiTestsConfig = any> = TestSuiteRaw | (() => MaybePromise>); export type TestFunction = (env: RestTestConfigType['env']) => void; export type TestElement, RestTestConfigType extends GreenDotApiTestsConfig> = Test | TestFn | TestSuite; export type TestEnvBase = { users: Record; } & Record; export interface GreenDotApiTestsConfig { mode: 'jsonRpc' | 'rest'; /** Solo mode is when you want to run a test alone from its config (you can also --filter='user' in the cli) You may want to disable solo mode for tests in CI since you don't want a forgot solo to mess out with test results */ disableSolo?: boolean; /** Api keys like configured in appConfig */ apiKeys?: GDapiKey; servers: { default: string; [serverNameShortcut: string]: string; }; env: ObjectGeneric; startAtTestNb?: number; afterTest?(testNb: number, env: ObjectGeneric): any; onError?(actualScenarioNb: number, env: ObjectGeneric): any; filter?: string; isReload?: boolean; restTestState?: Record; /** trigerred before the run */ onBeforeAllTests?(conf: { isReload: boolean; env: GD['testEnvType']; }): any; /** triggered BEFORE every tests */ onBeforeTest?(conf: { env: GD['testEnvType']; as?: GD['testUserNames'] | { email: string; password: string; }; apiKey?: GD['apiKeys']; headers: Record; }): any; /** triggered AFTER every tests */ onAfterTest?(conf: { env: GD['testEnvType']; as?: GD['testUserNames']; apiKey?: GD['apiKeys']; headers: Record; }): any; } export {};