From b9c2e0cd2e4f936adf9569c0b84dc2e695308424 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hartmut=20N=C3=B6renberg?= Date: Sun, 12 Apr 2026 18:04:21 +0200 Subject: [PATCH] fix(application): resolve typecheck errors in estimate-operations tests - Import EstimateStatus enum instead of using "DRAFT" string literal - Type BASE_VERSION fixture explicitly so lockedAt accepts Date | null - Add non-null assertion on mock.calls[0] to satisfy strict types - Reorder id/spread in version fixture to avoid duplicate property warning --- .../src/__tests__/estimate-operations.test.ts | 48 ++++++++++++------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/packages/application/src/__tests__/estimate-operations.test.ts b/packages/application/src/__tests__/estimate-operations.test.ts index 9961e3e..6d20398 100644 --- a/packages/application/src/__tests__/estimate-operations.test.ts +++ b/packages/application/src/__tests__/estimate-operations.test.ts @@ -1,4 +1,5 @@ import { describe, expect, it, vi } from "vitest"; +import { EstimateStatus } from "@capakraken/shared"; import { createEstimate } from "../use-cases/estimate/create-estimate.js"; import { cloneEstimate } from "../use-cases/estimate/clone-estimate.js"; import { listEstimates } from "../use-cases/estimate/list-estimates.js"; @@ -12,7 +13,24 @@ import { // Shared fixtures // --------------------------------------------------------------------------- -const BASE_VERSION = { +const BASE_VERSION: { + id: string; + estimateId: string; + versionNumber: number; + label: string; + status: string; + lockedAt: Date | null; + notes: string | null; + projectSnapshot: Record; + createdAt: Date; + updatedAt: Date; + assumptions: never[]; + scopeItems: never[]; + demandLines: never[]; + resourceSnapshots: never[]; + metrics: never[]; + exports: never[]; +} = { id: "ver_1", estimateId: "est_1", versionNumber: 1, @@ -84,7 +102,7 @@ describe("createEstimate", () => { projectId: "proj_1", name: "My Estimate", baseCurrency: "USD", - status: "DRAFT" as const, + status: EstimateStatus.DRAFT, assumptions: [], scopeItems: [], demandLines: [], @@ -105,7 +123,7 @@ describe("createEstimate", () => { const db = makeDb(); await createEstimate(db as never, minimalInput); - const createData = db.estimate.create.mock.calls[0][0].data; + const createData = db.estimate.create.mock.calls[0]![0].data; expect(createData.projectId).toBe("proj_1"); }); @@ -175,7 +193,7 @@ describe("cloneEstimate", () => { const result = await cloneEstimate(db as never, { sourceEstimateId: "est_src" }); expect(db.estimate.create).toHaveBeenCalledOnce(); - const createData = db.estimate.create.mock.calls[0][0].data; + const createData = db.estimate.create.mock.calls[0]![0].data; expect(createData.name).toBe("Copy of Original"); expect(result.id).toBe("est_clone"); }); @@ -184,7 +202,7 @@ describe("cloneEstimate", () => { const db = makeDb(); await cloneEstimate(db as never, { sourceEstimateId: "est_src", name: "Custom Clone" }); - const createData = db.estimate.create.mock.calls[0][0].data; + const createData = db.estimate.create.mock.calls[0]![0].data; expect(createData.name).toBe("Custom Clone"); }); @@ -245,7 +263,7 @@ describe("listEstimates", () => { const db = makeDb(); await listEstimates(db as never, { projectId: "proj_1" }); - const where = db.estimate.findMany.mock.calls[0][0].where; + const where = db.estimate.findMany.mock.calls[0]![0].where; expect(where.projectId).toBe("proj_1"); }); @@ -253,7 +271,7 @@ describe("listEstimates", () => { const db = makeDb([]); await listEstimates(db as never, { status: "APPROVED" as never }); - const where = db.estimate.findMany.mock.calls[0][0].where; + const where = db.estimate.findMany.mock.calls[0]![0].where; expect(where.status).toBe("APPROVED"); }); @@ -261,7 +279,7 @@ describe("listEstimates", () => { const db = makeDb(); await listEstimates(db as never, { query: "alpha" }); - const where = db.estimate.findMany.mock.calls[0][0].where; + const where = db.estimate.findMany.mock.calls[0]![0].where; expect(where.OR).toBeDefined(); expect(where.OR).toHaveLength(2); }); @@ -431,14 +449,12 @@ describe("createEstimateRevision", () => { ) { const txMock = { estimateVersion: { - create: vi - .fn() - .mockResolvedValue({ - id: "ver_new", - ...BASE_VERSION, - versionNumber: 2, - status: "WORKING", - }), + create: vi.fn().mockResolvedValue({ + ...BASE_VERSION, + id: "ver_new", + versionNumber: 2, + status: "WORKING", + }), }, estimateAssumption: { createMany: vi.fn().mockResolvedValue({}) }, scopeItem: { create: vi.fn().mockResolvedValue({ id: "scope_new" }) },