import {z} from 'zod' export type GetApiV1TestCasesTestCaseIdArgs = {test_case_id: string, version_id?: (string | null) | undefined, 'x-api-key'?: string | undefined}; export type GetApiV1TestCasesTestCaseIdOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const categoryReference = z.object({id: z.string(), name: z.string()}); export const testCaseVersionItem = z.object({id: z.string(), version_number: z.number().int(), created_at: z.string()}); export const testCaseVariableOutput = z.object({name: z.string(), type: z.string(), required: z.boolean().optional(), default: z.unknown(), description: z.string().max(200).nullable().optional()}); 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 getTestCaseResponse = z.object({id: z.string(), name: z.string(), steps: z.string(), expected_result: z.string(), description: z.string().nullable().optional(), priority: z.string().nullable().optional(), status: z.string().nullable().optional(), created_at: z.string().nullable().optional(), updated_at: z.string().nullable().optional(), category: categoryReference.nullable().optional(), versions: z.array(testCaseVersionItem).optional(), variables: z.array(testCaseVariableOutput).optional(), files: z.array(testCaseFileAttachmentOutput).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 }; /** * Get a test case * * GET /v1/test-cases/{test_case_id} */ export const getApiV1TestCasesTestCaseId = async (args: GetApiV1TestCasesTestCaseIdArgs, options?: GetApiV1TestCasesTestCaseIdOptions) => { const {baseUrl = "https://api.qualgent.ai", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.version_id != null) query.append("version_id", String(args.version_id)) 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: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getTestCaseResponse, await res.json()) };