Files
huskies/frontend/src/api/workflow.ts
T

164 lines
3.7 KiB
TypeScript
Raw Normal View History

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;
}
2026-02-19 14:45:57 +00:00
export interface CoverageReportResponse {
current_percent: number;
threshold_percent: number;
baseline_percent?: number | null;
}
export interface AcceptanceResponse {
can_accept: boolean;
reasons: string[];
warning?: string | null;
summary: TestRunSummaryResponse;
missing_categories: string[];
2026-02-19 14:45:57 +00:00
coverage_report?: CoverageReportResponse | null;
}
export interface ReviewStory {
story_id: string;
can_accept: boolean;
reasons: string[];
warning?: string | null;
summary: TestRunSummaryResponse;
missing_categories: string[];
2026-02-19 14:45:57 +00:00
coverage_report?: CoverageReportResponse | null;
}
export interface RecordCoveragePayload {
story_id: string;
current_percent: number;
threshold_percent?: number | null;
}
export interface CollectCoverageRequest {
story_id: string;
threshold_percent?: number | null;
}
export interface ReviewListResponse {
stories: ReviewStory[];
}
export interface StoryTodosResponse {
story_id: string;
story_name: string | null;
todos: string[];
}
export interface TodoListResponse {
stories: StoryTodosResponse[];
}
2026-02-19 15:51:12 +00:00
export interface UpcomingStory {
story_id: string;
name: string | null;
}
export interface UpcomingStoriesResponse {
stories: UpcomingStory[];
}
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 = {
2026-02-19 14:45:57 +00:00
collectCoverage(payload: CollectCoverageRequest, baseUrl?: string) {
return requestJson<CoverageReportResponse>(
"/workflow/coverage/collect",
{ method: "POST", body: JSON.stringify(payload) },
baseUrl,
);
},
recordCoverage(payload: RecordCoveragePayload, baseUrl?: string) {
return requestJson<boolean>(
"/workflow/coverage/record",
{ method: "POST", body: JSON.stringify(payload) },
baseUrl,
);
},
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);
},
2026-02-19 15:51:12 +00:00
getUpcomingStories(baseUrl?: string) {
return requestJson<UpcomingStoriesResponse>(
"/workflow/upcoming",
{},
baseUrl,
);
},
ensureAcceptance(payload: AcceptanceRequest, baseUrl?: string) {
return requestJson<boolean>(
"/workflow/acceptance/ensure",
{ method: "POST", body: JSON.stringify(payload) },
baseUrl,
);
},
getStoryTodos(baseUrl?: string) {
return requestJson<TodoListResponse>("/workflow/todos", {}, baseUrl);
},
};