feat(v2.4): 切换测试与缺陷主写
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
import { api } from './api';
|
||||
import type { Bug, BugSeverity, BugStatus } from './bug';
|
||||
import type { DevTask, DevTaskStatus, Reference } from './dev-task';
|
||||
import type { Priority } from './derive';
|
||||
import type { Requirement, RequirementStatus, SourceType } from './requirement';
|
||||
import type { TestCase, TestCaseStatus } from './test-case';
|
||||
import type { VersionPlan, VersionPlanLog, VersionPlanRequirementCoverage } from './version-plan';
|
||||
import type { WorkActivity, WorkActivityCategory, WorkActivitySourceType } from './work-activity';
|
||||
|
||||
@@ -194,6 +196,52 @@ interface DomainDevTaskRow {
|
||||
updatedAt?: string | Date | null;
|
||||
}
|
||||
|
||||
interface DomainTestCaseRow {
|
||||
id: string;
|
||||
versionId: string;
|
||||
requirementId?: string | null;
|
||||
categoryId?: string | null;
|
||||
code: string;
|
||||
title: string;
|
||||
description?: string | null;
|
||||
status?: string | null;
|
||||
roundNo?: number | null;
|
||||
priority?: string | number | null;
|
||||
assigneeId?: string | null;
|
||||
creatorId?: string | null;
|
||||
plannedTestAt?: string | Date | null;
|
||||
plannedEndAt?: string | Date | null;
|
||||
startedAt?: string | Date | null;
|
||||
completedAt?: string | Date | null;
|
||||
estimateHours?: number | null;
|
||||
aiEstimateHours?: number | null;
|
||||
references?: unknown;
|
||||
aiDraft?: boolean | null;
|
||||
aiDraftAt?: string | Date | null;
|
||||
createdAt?: string | Date | null;
|
||||
updatedAt?: string | Date | null;
|
||||
}
|
||||
|
||||
interface DomainBugRow {
|
||||
id: string;
|
||||
versionId: string;
|
||||
testCaseId?: string | null;
|
||||
code: string;
|
||||
title: string;
|
||||
description?: string | null;
|
||||
status?: string | null;
|
||||
severity?: string | null;
|
||||
priority?: string | number | null;
|
||||
assigneeId?: string | null;
|
||||
reporterId?: string | null;
|
||||
plannedFixAt?: string | Date | null;
|
||||
resolvedAt?: string | Date | null;
|
||||
closedAt?: string | Date | null;
|
||||
resolution?: string | null;
|
||||
createdAt?: string | Date | null;
|
||||
updatedAt?: string | Date | null;
|
||||
}
|
||||
|
||||
interface DomainWorkActivityRow {
|
||||
id: string;
|
||||
actorId?: string | null;
|
||||
@@ -211,6 +259,11 @@ interface DomainMutationResponse<T> {
|
||||
activities?: DomainWorkActivityRow[];
|
||||
}
|
||||
|
||||
interface DomainBatchMutationResponse<T> {
|
||||
items: T[];
|
||||
activities?: DomainWorkActivityRow[];
|
||||
}
|
||||
|
||||
export async function listVersionPlansByVersionId(versionId: string): Promise<VersionPlan[]> {
|
||||
const rows = await api.get<DomainVersionPlanRow[]>(`/versions/${versionId}/plans`);
|
||||
return rows.map(normalizeVersionPlan);
|
||||
@@ -301,6 +354,88 @@ export async function deleteDevTaskByVersionId(versionId: string, taskId: string
|
||||
await api.delete(`/versions/${versionId}/dev-tasks/${taskId}`);
|
||||
}
|
||||
|
||||
export async function listTestCasesByVersionId(versionId: string): Promise<TestCase[]> {
|
||||
const rows = await api.get<DomainTestCaseRow[]>(`/versions/${versionId}/test-cases`);
|
||||
return rows.map(normalizeTestCase);
|
||||
}
|
||||
|
||||
export async function createTestCaseByVersionId(versionId: string, data: Partial<TestCase>) {
|
||||
return normalizeMutation(
|
||||
await api.post<DomainMutationResponse<DomainTestCaseRow>>(`/versions/${versionId}/test-cases`, toTestCasePayload(data)),
|
||||
normalizeTestCase,
|
||||
);
|
||||
}
|
||||
|
||||
export async function createTestCasesByVersionId(versionId: string, items: Partial<TestCase>[]) {
|
||||
return normalizeBatchMutation(
|
||||
await api.post<DomainBatchMutationResponse<DomainTestCaseRow>>(
|
||||
`/versions/${versionId}/test-cases/batch`,
|
||||
{ items: items.map(toTestCasePayload) },
|
||||
),
|
||||
normalizeTestCase,
|
||||
);
|
||||
}
|
||||
|
||||
export async function updateTestCaseByVersionId(versionId: string, testCaseId: string, data: Partial<TestCase>) {
|
||||
return normalizeMutation(
|
||||
await api.patch<DomainMutationResponse<DomainTestCaseRow>>(`/versions/${versionId}/test-cases/${testCaseId}`, toTestCasePayload(data)),
|
||||
normalizeTestCase,
|
||||
);
|
||||
}
|
||||
|
||||
export async function updateTestCaseStatusByVersionId(versionId: string, testCaseId: string, status: TestCaseStatus) {
|
||||
return normalizeMutation(
|
||||
await api.patch<DomainMutationResponse<DomainTestCaseRow>>(`/versions/${versionId}/test-cases/${testCaseId}/status`, { status }),
|
||||
normalizeTestCase,
|
||||
);
|
||||
}
|
||||
|
||||
export async function deleteTestCaseByVersionId(versionId: string, testCaseId: string): Promise<void> {
|
||||
await api.delete(`/versions/${versionId}/test-cases/${testCaseId}`);
|
||||
}
|
||||
|
||||
export async function listBugsByVersionId(versionId: string): Promise<Bug[]> {
|
||||
const rows = await api.get<DomainBugRow[]>(`/versions/${versionId}/bugs`);
|
||||
return rows.map(normalizeBug);
|
||||
}
|
||||
|
||||
export async function createBugByVersionId(versionId: string, data: Partial<Bug>) {
|
||||
return normalizeMutation(
|
||||
await api.post<DomainMutationResponse<DomainBugRow>>(`/versions/${versionId}/bugs`, toBugPayload(data)),
|
||||
normalizeBug,
|
||||
);
|
||||
}
|
||||
|
||||
export async function updateBugByVersionId(versionId: string, bugId: string, data: Partial<Bug>) {
|
||||
return normalizeMutation(
|
||||
await api.patch<DomainMutationResponse<DomainBugRow>>(`/versions/${versionId}/bugs/${bugId}`, toBugPayload(data)),
|
||||
normalizeBug,
|
||||
);
|
||||
}
|
||||
|
||||
export async function updateBugStatusByVersionId(
|
||||
versionId: string,
|
||||
bugId: string,
|
||||
status: BugStatus,
|
||||
options: { operator?: string; resolution?: string } = {},
|
||||
) {
|
||||
return normalizeMutation(
|
||||
await api.patch<DomainMutationResponse<DomainBugRow>>(`/versions/${versionId}/bugs/${bugId}/status`, { status, ...options }),
|
||||
normalizeBug,
|
||||
);
|
||||
}
|
||||
|
||||
export async function transferBugByVersionId(versionId: string, bugId: string, assigneeId: string, operator?: string) {
|
||||
return normalizeMutation(
|
||||
await api.patch<DomainMutationResponse<DomainBugRow>>(`/versions/${versionId}/bugs/${bugId}/transfer`, { assigneeId, operator }),
|
||||
normalizeBug,
|
||||
);
|
||||
}
|
||||
|
||||
export async function deleteBugByVersionId(versionId: string, bugId: string): Promise<void> {
|
||||
await api.delete(`/versions/${versionId}/bugs/${bugId}`);
|
||||
}
|
||||
|
||||
function normalizeProductRoot(product: RootProduct): RootProduct {
|
||||
return {
|
||||
...product,
|
||||
@@ -508,6 +643,116 @@ function toDevTaskStatus(value: string | null | undefined): DevTaskStatus {
|
||||
return value === 'in_progress' || value === 'testing' || value === 'submitted' ? value : 'todo';
|
||||
}
|
||||
|
||||
function toTestCasePayload(data: Partial<TestCase>) {
|
||||
return {
|
||||
...(data.versionId !== undefined && { versionId: data.versionId }),
|
||||
...(data.requirementId !== undefined && { requirementId: data.requirementId }),
|
||||
...(data.categoryId !== undefined && { categoryId: data.categoryId }),
|
||||
...(data.caseNo !== undefined && { caseNo: data.caseNo }),
|
||||
...(data.title !== undefined && { title: data.title }),
|
||||
...(data.description !== undefined && { description: data.description }),
|
||||
...(data.status !== undefined && { status: data.status }),
|
||||
...(data.roundNo !== undefined && { roundNo: data.roundNo }),
|
||||
...(data.priority !== undefined && { priority: priorityToNumber(data.priority) }),
|
||||
...(data.assigneeId !== undefined && { assigneeId: data.assigneeId }),
|
||||
...(data.createdBy !== undefined && { createdBy: data.createdBy }),
|
||||
...(data.plannedTestAt !== undefined && { plannedTestAt: data.plannedTestAt }),
|
||||
...(data.plannedEndAt !== undefined && { plannedEndAt: data.plannedEndAt }),
|
||||
...(data.startedAt !== undefined && { startedAt: data.startedAt }),
|
||||
...(data.completedAt !== undefined && { completedAt: data.completedAt }),
|
||||
...(data.estimateHours !== undefined && { estimateHours: data.estimateHours }),
|
||||
...(data.aiEstimateHours !== undefined && { aiEstimateHours: data.aiEstimateHours }),
|
||||
...(data.references !== undefined && { references: data.references }),
|
||||
...(data.aiDraft !== undefined && { aiDraft: data.aiDraft }),
|
||||
...(data.aiDraftAt !== undefined && { aiDraftAt: data.aiDraftAt }),
|
||||
};
|
||||
}
|
||||
|
||||
function normalizeTestCase(row: DomainTestCaseRow): TestCase {
|
||||
return {
|
||||
id: row.id,
|
||||
caseNo: row.code,
|
||||
versionId: row.versionId,
|
||||
requirementId: row.requirementId ?? undefined,
|
||||
roundNo: row.roundNo && row.roundNo > 0 ? Math.floor(row.roundNo) : 1,
|
||||
title: row.title,
|
||||
description: row.description ?? '',
|
||||
categoryId: row.categoryId ?? '',
|
||||
priority: toPriority(row.priority),
|
||||
assigneeId: row.assigneeId ?? undefined,
|
||||
status: toTestCaseStatus(row.status),
|
||||
estimateHours: row.estimateHours ?? undefined,
|
||||
aiEstimateHours: row.aiEstimateHours ?? undefined,
|
||||
plannedTestAt: optionalIso(row.plannedTestAt),
|
||||
plannedEndAt: optionalIso(row.plannedEndAt),
|
||||
startedAt: optionalIso(row.startedAt),
|
||||
completedAt: optionalIso(row.completedAt),
|
||||
executedAt: optionalIso(row.completedAt),
|
||||
references: asArray<Reference>(row.references),
|
||||
aiDraft: Boolean(row.aiDraft),
|
||||
aiDraftAt: optionalIso(row.aiDraftAt),
|
||||
createdBy: row.creatorId ?? '',
|
||||
createdAt: isoString(row.createdAt),
|
||||
updatedAt: isoString(row.updatedAt),
|
||||
};
|
||||
}
|
||||
|
||||
function toTestCaseStatus(value: string | null | undefined): TestCaseStatus {
|
||||
if (value === 'running' || value === 'passed' || value === 'failed' || value === 'blocked') return value;
|
||||
return 'pending';
|
||||
}
|
||||
|
||||
function toBugPayload(data: Partial<Bug>) {
|
||||
return {
|
||||
...(data.versionId !== undefined && { versionId: data.versionId }),
|
||||
...(data.testCaseId !== undefined && { testCaseId: data.testCaseId }),
|
||||
...(data.bugNo !== undefined && { bugNo: data.bugNo }),
|
||||
...(data.title !== undefined && { title: data.title }),
|
||||
...(data.description !== undefined && { description: data.description }),
|
||||
...(data.status !== undefined && { status: data.status }),
|
||||
...(data.severity !== undefined && { severity: data.severity }),
|
||||
...(data.priority !== undefined && { priority: priorityToNumber(data.priority) }),
|
||||
...(data.assigneeId !== undefined && { assigneeId: data.assigneeId }),
|
||||
...(data.reportedBy !== undefined && { reportedBy: data.reportedBy }),
|
||||
...(data.plannedFixAt !== undefined && { plannedFixAt: data.plannedFixAt }),
|
||||
...(data.resolvedAt !== undefined && { resolvedAt: data.resolvedAt }),
|
||||
...(data.closedAt !== undefined && { closedAt: data.closedAt }),
|
||||
...(data.resolution !== undefined && { resolution: data.resolution }),
|
||||
};
|
||||
}
|
||||
|
||||
function normalizeBug(row: DomainBugRow): Bug {
|
||||
return {
|
||||
id: row.id,
|
||||
bugNo: row.code,
|
||||
versionId: row.versionId,
|
||||
testCaseId: row.testCaseId ?? '',
|
||||
title: row.title,
|
||||
description: row.description ?? '',
|
||||
severity: toBugSeverity(row.severity),
|
||||
priority: toPriority(row.priority),
|
||||
reportedBy: row.reporterId ?? '',
|
||||
assigneeId: row.assigneeId ?? '',
|
||||
status: toBugStatus(row.status),
|
||||
resolvedAt: optionalIso(row.resolvedAt),
|
||||
closedAt: optionalIso(row.closedAt),
|
||||
resolution: row.resolution ?? undefined,
|
||||
plannedFixAt: optionalIso(row.plannedFixAt),
|
||||
createdAt: isoString(row.createdAt),
|
||||
updatedAt: isoString(row.updatedAt),
|
||||
};
|
||||
}
|
||||
|
||||
function toBugStatus(value: string | null | undefined): BugStatus {
|
||||
if (value === 'fixing' || value === 'fixed' || value === 'verifying' || value === 'closed' || value === 'rejected') return value;
|
||||
return 'open';
|
||||
}
|
||||
|
||||
function toBugSeverity(value: string | null | undefined): BugSeverity {
|
||||
if (value === 'critical' || value === 'major' || value === 'trivial') return value;
|
||||
return 'minor';
|
||||
}
|
||||
|
||||
function normalizeMutation<Row, Item>(
|
||||
response: DomainMutationResponse<Row>,
|
||||
mapper: (row: Row) => Item,
|
||||
@@ -518,6 +763,16 @@ function normalizeMutation<Row, Item>(
|
||||
};
|
||||
}
|
||||
|
||||
function normalizeBatchMutation<Row, Item>(
|
||||
response: DomainBatchMutationResponse<Row>,
|
||||
mapper: (row: Row) => Item,
|
||||
): { items: Item[]; activities: WorkActivity[] } {
|
||||
return {
|
||||
items: (response.items ?? []).map(mapper),
|
||||
activities: (response.activities ?? []).map(normalizeWorkActivity),
|
||||
};
|
||||
}
|
||||
|
||||
function normalizeWorkActivity(row: DomainWorkActivityRow): WorkActivity {
|
||||
const metadata = isRecord(row.metadata) ? row.metadata : {};
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user