feat: 完善历史任务页与删除能力
This commit is contained in:
@@ -285,4 +285,61 @@ describe("API server", () => {
|
||||
|
||||
await app.close();
|
||||
});
|
||||
|
||||
it("deletes a task together with its report snapshots", async () => {
|
||||
const app = createServer();
|
||||
await app.ready();
|
||||
|
||||
const createdTask = await createTask(app, "Xbox Series X");
|
||||
|
||||
const candidatesResponse = await app.inject({
|
||||
method: "GET",
|
||||
url: `/api/tasks/${createdTask.taskId}/candidates`
|
||||
});
|
||||
const firstCandidateId = candidatesResponse.json().candidates.tmall[0].candidateId;
|
||||
|
||||
await app.inject({
|
||||
method: "POST",
|
||||
url: `/api/tasks/${createdTask.taskId}/confirm`,
|
||||
payload: {
|
||||
selections: [
|
||||
{
|
||||
platform: "tmall",
|
||||
candidateIds: [firstCandidateId]
|
||||
}
|
||||
]
|
||||
}
|
||||
});
|
||||
|
||||
const deleteResponse = await app.inject({
|
||||
method: "DELETE",
|
||||
url: `/api/tasks/${createdTask.taskId}`
|
||||
});
|
||||
|
||||
expect(deleteResponse.statusCode).toBe(204);
|
||||
|
||||
const taskResponse = await app.inject({
|
||||
method: "GET",
|
||||
url: `/api/tasks/${createdTask.taskId}`
|
||||
});
|
||||
expect(taskResponse.statusCode).toBe(404);
|
||||
|
||||
const reportResponse = await app.inject({
|
||||
method: "GET",
|
||||
url: `/api/tasks/${createdTask.taskId}/report`
|
||||
});
|
||||
expect(reportResponse.statusCode).toBe(404);
|
||||
|
||||
const historyResponse = await app.inject({
|
||||
method: "GET",
|
||||
url: "/api/history"
|
||||
});
|
||||
expect(
|
||||
historyResponse
|
||||
.json()
|
||||
.tasks.some((task: { taskId: string }) => task.taskId === createdTask.taskId)
|
||||
).toBe(false);
|
||||
|
||||
await app.close();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -54,6 +54,19 @@ export function createServer() {
|
||||
return { task };
|
||||
});
|
||||
|
||||
app.delete<{
|
||||
Params: { taskId: string };
|
||||
}>("/api/tasks/:taskId", async (request, reply) => {
|
||||
try {
|
||||
store.deleteTask(request.params.taskId);
|
||||
reply.code(204);
|
||||
return null;
|
||||
} catch {
|
||||
reply.code(404);
|
||||
return { message: "Task not found." };
|
||||
}
|
||||
});
|
||||
|
||||
app.get<{
|
||||
Params: { taskId: string };
|
||||
}>("/api/tasks/:taskId/candidates", async (request, reply) => {
|
||||
|
||||
@@ -311,6 +311,14 @@ export class InMemoryTaskStore {
|
||||
return reports[reports.length - 1];
|
||||
}
|
||||
|
||||
deleteTask(taskId: string): void {
|
||||
this.requireTask(taskId);
|
||||
this.tasks.delete(taskId);
|
||||
this.reports.delete(taskId);
|
||||
this.reportFingerprints.delete(taskId);
|
||||
this.executionScenarios.delete(taskId);
|
||||
}
|
||||
|
||||
private runSearch(task: TaskRecord): void {
|
||||
task.taskStage = "search";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user