102 lines
2.2 KiB
TypeScript
102 lines
2.2 KiB
TypeScript
|
|
export type TestStatus = "pass" | "fail";
|
||
|
|
|
||
|
|
export interface TestCasePayload {
|
||
|
|
name: string;
|
||
|
|
status: TestStatus;
|
||
|
|
details?: string | null;
|
||
|
|
}
|
||
|
|
|
||
|
|
export interface RecordTestsPayload {
|
||
|
|
story_id: string;
|
||
|
|
unit: TestCasePayload[];
|
||
|
|
integration: TestCasePayload[];
|
||
|
|
}
|
||
|
|
|
||
|
|
export interface AcceptanceRequest {
|
||
|
|
story_id: string;
|
||
|
|
}
|
||
|
|
|
||
|
|
export interface TestRunSummaryResponse {
|
||
|
|
total: number;
|
||
|
|
passed: number;
|
||
|
|
failed: number;
|
||
|
|
}
|
||
|
|
|
||
|
|
export interface AcceptanceResponse {
|
||
|
|
can_accept: boolean;
|
||
|
|
reasons: string[];
|
||
|
|
warning?: string | null;
|
||
|
|
summary: TestRunSummaryResponse;
|
||
|
|
missing_categories: string[];
|
||
|
|
}
|
||
|
|
|
||
|
|
export interface ReviewStory {
|
||
|
|
story_id: string;
|
||
|
|
can_accept: boolean;
|
||
|
|
reasons: string[];
|
||
|
|
warning?: string | null;
|
||
|
|
summary: TestRunSummaryResponse;
|
||
|
|
missing_categories: string[];
|
||
|
|
}
|
||
|
|
|
||
|
|
export interface ReviewListResponse {
|
||
|
|
stories: ReviewStory[];
|
||
|
|
}
|
||
|
|
|
||
|
|
const DEFAULT_API_BASE = "/api";
|
||
|
|
|
||
|
|
function buildApiUrl(path: string, baseUrl = DEFAULT_API_BASE): string {
|
||
|
|
return `${baseUrl}${path}`;
|
||
|
|
}
|
||
|
|
|
||
|
|
async function requestJson<T>(
|
||
|
|
path: string,
|
||
|
|
options: RequestInit = {},
|
||
|
|
baseUrl = DEFAULT_API_BASE,
|
||
|
|
): Promise<T> {
|
||
|
|
const res = await fetch(buildApiUrl(path, baseUrl), {
|
||
|
|
headers: {
|
||
|
|
"Content-Type": "application/json",
|
||
|
|
...(options.headers ?? {}),
|
||
|
|
},
|
||
|
|
...options,
|
||
|
|
});
|
||
|
|
|
||
|
|
if (!res.ok) {
|
||
|
|
const text = await res.text();
|
||
|
|
throw new Error(text || `Request failed (${res.status})`);
|
||
|
|
}
|
||
|
|
|
||
|
|
return res.json() as Promise<T>;
|
||
|
|
}
|
||
|
|
|
||
|
|
export const workflowApi = {
|
||
|
|
recordTests(payload: RecordTestsPayload, baseUrl?: string) {
|
||
|
|
return requestJson<boolean>(
|
||
|
|
"/workflow/tests/record",
|
||
|
|
{ method: "POST", body: JSON.stringify(payload) },
|
||
|
|
baseUrl,
|
||
|
|
);
|
||
|
|
},
|
||
|
|
getAcceptance(payload: AcceptanceRequest, baseUrl?: string) {
|
||
|
|
return requestJson<AcceptanceResponse>(
|
||
|
|
"/workflow/acceptance",
|
||
|
|
{ method: "POST", body: JSON.stringify(payload) },
|
||
|
|
baseUrl,
|
||
|
|
);
|
||
|
|
},
|
||
|
|
getReviewQueue(baseUrl?: string) {
|
||
|
|
return requestJson<ReviewListResponse>("/workflow/review", {}, baseUrl);
|
||
|
|
},
|
||
|
|
getReviewQueueAll(baseUrl?: string) {
|
||
|
|
return requestJson<ReviewListResponse>("/workflow/review/all", {}, baseUrl);
|
||
|
|
},
|
||
|
|
ensureAcceptance(payload: AcceptanceRequest, baseUrl?: string) {
|
||
|
|
return requestJson<boolean>(
|
||
|
|
"/workflow/acceptance/ensure",
|
||
|
|
{ method: "POST", body: JSON.stringify(payload) },
|
||
|
|
baseUrl,
|
||
|
|
);
|
||
|
|
},
|
||
|
|
};
|