import {z} from 'zod' export type TestCase = {id?: number | undefined, title?: string | undefined, sort_index?: number | undefined, is_deleted?: boolean | undefined, created_at?: string | undefined, created_by?: number | undefined, modified_at?: string | undefined, modified_by?: number | undefined, deleted_at?: string | undefined, deleted_by?: number | undefined, _etag: string, project_id?: number | undefined, owner_user_id?: number | undefined, $owner_name?: string | undefined, type?: string | undefined, template?: string | undefined, precondition_text?: string | undefined, content_text?: string | undefined, steps_text?: string | undefined, expected_result_text?: string | undefined, bdd_scenarios_text?: string | undefined, priority?: number | undefined, status?: string | undefined, testcase_type?: string | undefined, automation?: string | undefined, estimate?: number | undefined}; export type CreateApiTestcaseBulkUndeleteArgs = {body: Array}; export type CreateApiTestcaseBulkUndeleteOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const testCase = z.object({id: z.number().int().gte(0).optional(), title: z.string().optional(), sort_index: z.number().optional(), is_deleted: z.boolean().optional(), created_at: z.string().optional(), created_by: z.number().optional(), modified_at: z.string().optional(), modified_by: z.number().optional(), deleted_at: z.string().optional(), deleted_by: z.number().optional(), _etag: z.string(), project_id: z.number().int().gte(0).optional(), owner_user_id: z.number().int().gte(0).optional(), $owner_name: z.string().optional(), type: z.string().optional(), template: z.string().optional(), precondition_text: z.string().optional(), content_text: z.string().optional(), steps_text: z.string().optional(), expected_result_text: z.string().optional(), bdd_scenarios_text: z.string().optional(), priority: z.number().optional(), status: z.string().optional(), testcase_type: z.string().optional(), automation: z.string().optional(), estimate: z.number().optional()}); export const createApiTestcaseBulkUndeleteResponse = z.array(testCase); 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 }; /** * Undeletes multiple 'TestCase' entities * * POST /testcase/bulk/undelete */ export const createApiTestcaseBulkUndelete = async (args: CreateApiTestcaseBulkUndeleteArgs, options?: CreateApiTestcaseBulkUndeleteOptions) => { 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 (ApiKeyAuth !== undefined) headers.set("X-Api-Key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/testcase/bulk/undelete${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(createApiTestcaseBulkUndeleteResponse, await res.json()) };