import {z} from 'zod' export type AutomationKeyRawFields = {[key: string]: string | number | boolean | null}; export type AutomationTestRun = {id?: number | undefined, title?: string | undefined, project_id?: number | undefined, closed_at?: string | undefined, closed_by?: number | undefined, is_closed?: boolean | undefined, tags?: string | undefined, atm_source_id?: number | undefined, min_timestamp?: number | undefined, max_timestamp?: number | undefined, last_update_timestamp?: number | undefined, duration?: number | undefined, status_highest?: number | undefined, is_completed?: boolean | undefined, is_pinned?: boolean | undefined, key_fields_raw?: (AutomationKeyRawFields | null) | undefined, description?: (string | null) | undefined, stat_passed_count?: number | undefined, stat_passed_warn_count?: number | undefined, stat_skipped_count?: number | undefined, stat_blocked_count?: number | undefined, stat_failed_count?: number | undefined}; export type UpdateApiAtmTestrunIdArgs = {id: number, force?: boolean | undefined, body: AutomationTestRun}; export type UpdateApiAtmTestrunIdOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const automationKeyRawFields = z.record(z.string(), z.union([z.string(), z.number(), z.boolean()]).nullable()); export const automationTestRun = z.object({id: z.number().int().gte(0).optional(), title: z.string().optional(), project_id: z.number().int().gte(0).optional(), closed_at: z.string().optional(), closed_by: z.number().optional(), is_closed: z.boolean().optional(), tags: z.string().optional(), atm_source_id: z.number().int().gte(0).optional(), min_timestamp: z.number().optional(), max_timestamp: z.number().optional(), last_update_timestamp: z.number().optional(), duration: z.number().optional(), status_highest: z.number().optional(), is_completed: z.boolean().optional(), is_pinned: z.boolean().optional(), key_fields_raw: automationKeyRawFields.nullable().optional(), description: z.string().nullable().optional(), stat_passed_count: z.number().optional(), stat_passed_warn_count: z.number().optional(), stat_skipped_count: z.number().optional(), stat_blocked_count: z.number().optional(), stat_failed_count: z.number().optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Update one 'AutomationTestRun' entity * * PUT /atm-testrun/{id} */ export const updateApiAtmTestrunId = async (args: UpdateApiAtmTestrunIdArgs, options?: UpdateApiAtmTestrunIdOptions) => { const {baseUrl = "https://app.testiny.io/api/v1", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.force != null) query.append("force", String(args.force)) if (ApiKeyAuth !== undefined) headers.set("X-Api-Key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/atm-testrun/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(automationTestRun, await res.json()) };