From a37d6fc96be1c0abf52d033a2c4480aa28fdf383 Mon Sep 17 00:00:00 2001 From: david Date: Fri, 28 Aug 2026 13:02:46 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20actualizar=20m=C3=A9todos=20para=20incl?= =?UTF-8?q?uir=20proformas=20archivadas=20y=20agregar=20pruebas=20correspo?= =?UTF-8?q?ndientes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../preview-proforma-report.use-case.test.ts | 43 +++++++++++++++++++ .../preview-proforma-report.use-case.ts | 6 +-- .../report-proforma-pdf.use-case.test.ts | 43 +++++++++++++++++++ .../use-cases/report-proforma-pdf.use-case.ts | 6 +-- .../api/unarchive-proforma-by-id.api.test.ts | 29 +++++++++++++ .../api/unarchive-proforma-by-id.api.ts | 6 ++- 6 files changed, 125 insertions(+), 8 deletions(-) create mode 100644 modules/customer-invoices/src/api/application/proformas/use-cases/preview-proforma-report.use-case.test.ts create mode 100644 modules/customer-invoices/src/api/application/proformas/use-cases/report-proforma-pdf.use-case.test.ts create mode 100644 modules/customer-invoices/src/web/proformas/shared/api/unarchive-proforma-by-id.api.test.ts diff --git a/modules/customer-invoices/src/api/application/proformas/use-cases/preview-proforma-report.use-case.test.ts b/modules/customer-invoices/src/api/application/proformas/use-cases/preview-proforma-report.use-case.test.ts new file mode 100644 index 00000000..96addf38 --- /dev/null +++ b/modules/customer-invoices/src/api/application/proformas/use-cases/preview-proforma-report.use-case.test.ts @@ -0,0 +1,43 @@ +import assert from "node:assert/strict"; +import test from "node:test"; + +import { UniqueID } from "@repo/rdx-ddd"; +import { Result } from "@repo/rdx-utils"; + +import { PreviewProformaReportUseCase } from "./preview-proforma-report.use-case"; + +test("busca proformas archivadas al generar la vista previa", async () => { + let activeFinderCalls = 0; + let includingArchivedFinderCalls = 0; + const expectedError = new Error("Proforma not found"); + const useCase = new PreviewProformaReportUseCase({ + finder: { + findProformaById: async () => { + activeFinderCalls += 1; + return Result.fail(new Error("Active finder should not be called")); + }, + findProformaByIdIncludingArchived: async () => { + includingArchivedFinderCalls += 1; + return Result.fail(expectedError); + }, + }, + companyReportProfileFinder: {} as never, + fullReadModelAssembler: {} as never, + fullSnapshotBuilder: {} as never, + reportSnapshotBuilder: {} as never, + documentService: {} as never, + transactionManager: { + complete: async (work) => work({} as never), + }, + }); + + const result = await useCase.execute({ + companyId: UniqueID.generateNewID(), + proforma_id: UniqueID.generateNewID().toString(), + }); + + assert.equal(result.isFailure, true); + assert.equal(result.error, expectedError); + assert.equal(activeFinderCalls, 0); + assert.equal(includingArchivedFinderCalls, 1); +}); diff --git a/modules/customer-invoices/src/api/application/proformas/use-cases/preview-proforma-report.use-case.ts b/modules/customer-invoices/src/api/application/proformas/use-cases/preview-proforma-report.use-case.ts index fff8a896..11cd3f26 100644 --- a/modules/customer-invoices/src/api/application/proformas/use-cases/preview-proforma-report.use-case.ts +++ b/modules/customer-invoices/src/api/application/proformas/use-cases/preview-proforma-report.use-case.ts @@ -1,15 +1,15 @@ import type { ITransactionManager } from "@erp/core/api"; import { UniqueID } from "@repo/rdx-ddd"; -import { Maybe, Result } from "@repo/rdx-utils"; +import { type Maybe, Result } from "@repo/rdx-utils"; import { CompanyReportProfileNotFoundError } from "../errors"; +import type { ReportLocalization } from "../models"; import type { ICompanyReportProfileFinder, IProformaFinder, IProformaFullReadModelAssembler, ProformaDocumentGeneratorService, } from "../services"; -import type { ReportLocalization } from "../models"; import type { IProformaFullSnapshotBuilder } from "../snapshot-builders"; import type { IProformaReportSnapshotBuilder } from "../snapshot-builders/report"; @@ -44,7 +44,7 @@ export class PreviewProformaReportUseCase { return this.deps.transactionManager.complete(async (transaction) => { try { - const proformaResult = await this.deps.finder.findProformaById( + const proformaResult = await this.deps.finder.findProformaByIdIncludingArchived( companyId, proformaId, transaction diff --git a/modules/customer-invoices/src/api/application/proformas/use-cases/report-proforma-pdf.use-case.test.ts b/modules/customer-invoices/src/api/application/proformas/use-cases/report-proforma-pdf.use-case.test.ts new file mode 100644 index 00000000..2c83e354 --- /dev/null +++ b/modules/customer-invoices/src/api/application/proformas/use-cases/report-proforma-pdf.use-case.test.ts @@ -0,0 +1,43 @@ +import assert from "node:assert/strict"; +import test from "node:test"; + +import { UniqueID } from "@repo/rdx-ddd"; +import { Result } from "@repo/rdx-utils"; + +import { ReportProformaPdfUseCase } from "./report-proforma-pdf.use-case"; + +test("busca proformas archivadas al generar el PDF", async () => { + let activeFinderCalls = 0; + let includingArchivedFinderCalls = 0; + const expectedError = new Error("Proforma not found"); + const useCase = new ReportProformaPdfUseCase({ + finder: { + findProformaById: async () => { + activeFinderCalls += 1; + return Result.fail(new Error("Active finder should not be called")); + }, + findProformaByIdIncludingArchived: async () => { + includingArchivedFinderCalls += 1; + return Result.fail(expectedError); + }, + }, + companyReportProfileFinder: {} as never, + fullReadModelAssembler: {} as never, + fullSnapshotBuilder: {} as never, + reportSnapshotBuilder: {} as never, + documentService: {} as never, + transactionManager: { + complete: async (work) => work({} as never), + }, + }); + + const result = await useCase.execute({ + companyId: UniqueID.generateNewID(), + proforma_id: UniqueID.generateNewID().toString(), + }); + + assert.equal(result.isFailure, true); + assert.equal(result.error, expectedError); + assert.equal(activeFinderCalls, 0); + assert.equal(includingArchivedFinderCalls, 1); +}); diff --git a/modules/customer-invoices/src/api/application/proformas/use-cases/report-proforma-pdf.use-case.ts b/modules/customer-invoices/src/api/application/proformas/use-cases/report-proforma-pdf.use-case.ts index 75944099..e9d642c5 100644 --- a/modules/customer-invoices/src/api/application/proformas/use-cases/report-proforma-pdf.use-case.ts +++ b/modules/customer-invoices/src/api/application/proformas/use-cases/report-proforma-pdf.use-case.ts @@ -1,15 +1,15 @@ import type { ITransactionManager } from "@erp/core/api"; import { UniqueID } from "@repo/rdx-ddd"; -import { Maybe, Result } from "@repo/rdx-utils"; +import { type Maybe, Result } from "@repo/rdx-utils"; import { CompanyReportProfileNotFoundError } from "../errors"; +import type { ReportLocalization } from "../models"; import type { ICompanyReportProfileFinder, IProformaFinder, IProformaFullReadModelAssembler, ProformaDocumentGeneratorService, } from "../services"; -import type { ReportLocalization } from "../models"; import type { IProformaFullSnapshotBuilder } from "../snapshot-builders"; import type { IProformaReportSnapshotBuilder } from "../snapshot-builders/report"; @@ -44,7 +44,7 @@ export class ReportProformaPdfUseCase { return this.deps.transactionManager.complete(async (transaction) => { try { - const proformaResult = await this.deps.finder.findProformaById( + const proformaResult = await this.deps.finder.findProformaByIdIncludingArchived( companyId, proformaId, transaction diff --git a/modules/customer-invoices/src/web/proformas/shared/api/unarchive-proforma-by-id.api.test.ts b/modules/customer-invoices/src/web/proformas/shared/api/unarchive-proforma-by-id.api.test.ts new file mode 100644 index 00000000..011be9b5 --- /dev/null +++ b/modules/customer-invoices/src/web/proformas/shared/api/unarchive-proforma-by-id.api.test.ts @@ -0,0 +1,29 @@ +import assert from "node:assert/strict"; +import test from "node:test"; + +import type { IDataSource } from "@erp/core/client"; + +import { unarchiveProformaById } from "./unarchive-proforma-by-id.api"; + +test("envia la solicitud de desarchivado a la ruta esperada", async () => { + const calls: unknown[] = []; + const dataSource = { + custom: async (params: unknown) => { + calls.push(params); + return { id: "019fd66d-26e3-7388-8ff3-07d5609174b6" }; + }, + } as Pick; + + await unarchiveProformaById(dataSource as IDataSource, { + proformaId: "019fd66d-26e3-7388-8ff3-07d5609174b6", + }); + + assert.deepEqual(calls, [ + { + path: "proformas/019fd66d-26e3-7388-8ff3-07d5609174b6/unarchive", + method: "patch", + data: undefined, + signal: undefined, + }, + ]); +}); diff --git a/modules/customer-invoices/src/web/proformas/shared/api/unarchive-proforma-by-id.api.ts b/modules/customer-invoices/src/web/proformas/shared/api/unarchive-proforma-by-id.api.ts index ed5a78f6..85c67451 100644 --- a/modules/customer-invoices/src/web/proformas/shared/api/unarchive-proforma-by-id.api.ts +++ b/modules/customer-invoices/src/web/proformas/shared/api/unarchive-proforma-by-id.api.ts @@ -17,8 +17,10 @@ export const unarchiveProformaById = ( if (!proformaId) throw new Error("proformaId is required"); - return dataSource.custom(`proformas/${proformaId}/unarchive`, { - method: "PATCH", + return dataSource.custom({ + path: `proformas/${proformaId}/unarchive`, + method: "patch", + data: undefined, signal, }); };