import {z} from 'zod' export type TestStepInput = {description: string, credential_id?: (string | null) | undefined, kind?: ('setup' | 'act' | 'verify' | null) | undefined}; export type TestCaseVariableInput = {name: string, type: string, required?: boolean | undefined, default: unknown, description?: (string | null) | undefined}; export type TestCaseFileAttachmentInput = {file_id: string, description?: (string | null) | undefined}; export type UpdateTestCaseRequest = {name?: (string | null) | undefined, steps?: (Array | null) | undefined, expected_result?: (string | null) | undefined, priority?: (string | null) | undefined, description?: (string | null) | undefined, change_source?: (string | null) | undefined, variables?: (Array | null) | undefined, file_attachments?: (Array | null) | undefined, file_ids?: (Array | null) | undefined}; export type PatchApiV1TestCasesTestCaseIdArgs = {test_case_id: string, 'x-api-key'?: string | undefined, body: UpdateTestCaseRequest}; export type PatchApiV1TestCasesTestCaseIdOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const testCaseFileAttachmentOutput = z.object({file_id: z.string(), description: z.string().nullable().optional(), file_path: z.string().nullable().optional(), original_name: z.string().nullable().optional(), file_type: z.string().nullable().optional(), file_size: z.number().int().nullable().optional()}); export const variableWarning = z.object({code: z.string(), message: z.string()}); export const updateTestCaseResponse = z.object({id: z.string(), version_number: z.number().int(), version_id: z.string(), files: z.array(testCaseFileAttachmentOutput).optional(), warnings: z.array(variableWarning).nullable().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 a test case * * PATCH /v1/test-cases/{test_case_id} */ export const patchApiV1TestCasesTestCaseId = async (args: PatchApiV1TestCasesTestCaseIdArgs, options?: PatchApiV1TestCasesTestCaseIdOptions) => { const {baseUrl = "https://api.qualgent.ai", 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['x-api-key'] != null) headers.set("x-api-key", String(args['x-api-key'])) if (ApiKeyAuth !== undefined) headers.set("x-api-key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v1/test-cases/${encodeURIComponent(String(args.test_case_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(updateTestCaseResponse, await res.json()) };