export type CreateApiBranchTestResultsArgs = {branch: string, body: Record}; export type CreateApiBranchTestResultsOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * submit test results * * POST /{branch}/test-results */ export const createApiBranchTestResults = async (args: CreateApiBranchTestResultsArgs, options: CreateApiBranchTestResultsOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/${encodeURIComponent(String(args.branch))}/test-results${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 (await res.json()) as unknown };