feat: add inspection object resource workflow

This commit is contained in:
2026-08-13 16:51:48 +08:00
parent 3db84a7fb2
commit 29a69793db
11 changed files with 2312 additions and 935 deletions

View File

@@ -5,16 +5,10 @@ import type { TrpcContext } from "./_core/context";
vi.mock("./db", () => ({
findInspectionTaskByModelAndName: vi.fn(async () => undefined),
createInspectionTask: vi.fn(async (data) => ({
id: 1,
modelId: data.modelId,
name: data.name,
inspector: data.inspector ?? null,
notes: data.notes ?? null,
status: data.status,
createdAt: new Date(),
updatedAt: new Date(),
completedAt: null,
createInspectionTaskWithDefaults: vi.fn(async (data) => ({
task: { id: 1, modelId: data.modelId, inspectionObjectId: data.inspectionObjectId, name: data.name, inspector: data.inspector ?? null, notes: data.notes ?? null, status: data.status, createdAt: new Date(), updatedAt: new Date(), completedAt: null },
pointcloudFile: { id: 11, taskId: 1 },
cadFile: { id: 12, taskId: 1 },
})),
}));
@@ -60,13 +54,15 @@ describe("inspection task router", () => {
const result = await caller.inspectionTask.create({
modelId: 1,
inspectionObjectId: 9,
name: " 首检任务 ",
});
expect(result.status).toBe("created");
expect(result.task.status).toBe("created");
expect(db.findInspectionTaskByModelAndName).toHaveBeenCalledWith(1, "首检任务");
expect(db.createInspectionTask).toHaveBeenCalledWith({
expect(db.createInspectionTaskWithDefaults).toHaveBeenCalledWith({
modelId: 1,
inspectionObjectId: 9,
name: "首检任务",
inspector: null,
notes: null,
@@ -78,6 +74,7 @@ describe("inspection task router", () => {
vi.mocked(db.findInspectionTaskByModelAndName).mockResolvedValueOnce({
id: 1,
modelId: 1,
inspectionObjectId: 9,
name: "首检任务",
inspector: null,
notes: null,
@@ -92,17 +89,18 @@ describe("inspection task router", () => {
await expect(caller.inspectionTask.create({
modelId: 1,
inspectionObjectId: 9,
name: "首检任务",
})).rejects.toMatchObject({
code: "CONFLICT",
message: "该车型下已存在同名检测任务。",
});
expect(db.createInspectionTask).not.toHaveBeenCalled();
expect(db.createInspectionTaskWithDefaults).not.toHaveBeenCalled();
});
it("returns CONFLICT when the database unique key rejects a concurrent duplicate", async () => {
vi.mocked(db.createInspectionTask).mockRejectedValueOnce({
vi.mocked(db.createInspectionTaskWithDefaults).mockRejectedValueOnce({
code: "ER_DUP_ENTRY",
errno: 1062,
message: "Duplicate entry '1-首检任务' for key 'uk_inspection_tasks_model_name'",
@@ -113,6 +111,7 @@ describe("inspection task router", () => {
await expect(caller.inspectionTask.create({
modelId: 1,
inspectionObjectId: 9,
name: "首检任务",
})).rejects.toMatchObject({
code: "CONFLICT",