first commit
Some checks failed
Some checks failed
This commit is contained in:
52
app/lib/testcase-backend/store.ts
Normal file
52
app/lib/testcase-backend/store.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import type { Task, CreateTaskParams } from "./types";
|
||||
|
||||
const tasks = new Map<string, Task>();
|
||||
|
||||
export function getTask(taskId: string): Task | undefined {
|
||||
return tasks.get(taskId);
|
||||
}
|
||||
|
||||
export function setTask(taskId: string, task: Task): void {
|
||||
tasks.set(taskId, task);
|
||||
}
|
||||
|
||||
export function createTask(taskId: string, params: CreateTaskParams): Task {
|
||||
const task: Task = {
|
||||
id: taskId,
|
||||
status: "pending",
|
||||
title: params.title.trim(),
|
||||
englishName: params.englishName.trim().toLowerCase(),
|
||||
description: params.description.trim(),
|
||||
standardCode: params.standardCode.trim(),
|
||||
testCaseCount: params.testCaseCount,
|
||||
serviceLevel: params.serviceLevel || "standard",
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
progress: 0,
|
||||
errorMessage: null,
|
||||
generatedCases: 0,
|
||||
};
|
||||
tasks.set(taskId, task);
|
||||
return task;
|
||||
}
|
||||
|
||||
export function findRunningTaskByEnglishName(englishName: string): Task | undefined {
|
||||
const name = englishName.trim().toLowerCase();
|
||||
for (const task of tasks.values()) {
|
||||
if (task.englishName === name && (task.status === "pending" || task.status === "running")) {
|
||||
return task;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export function getEstimatedTime(serviceLevel: string, caseCount: number): number {
|
||||
const baseTime = Math.ceil(caseCount / 2);
|
||||
const multiplier: Record<string, number> = {
|
||||
standard: 1.0,
|
||||
domestic: 1.5,
|
||||
pro: 1.2,
|
||||
max: 2.0,
|
||||
};
|
||||
return Math.max(30, baseTime * (multiplier[serviceLevel] ?? 1.0));
|
||||
}
|
||||
Reference in New Issue
Block a user