feat: actualizar métodos para incluir proformas archivadas y agregar pruebas correspondientes
This commit is contained in:
parent
23c77adc80
commit
a37d6fc96b
@ -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);
|
||||||
|
});
|
||||||
@ -1,15 +1,15 @@
|
|||||||
import type { ITransactionManager } from "@erp/core/api";
|
import type { ITransactionManager } from "@erp/core/api";
|
||||||
import { UniqueID } from "@repo/rdx-ddd";
|
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 { CompanyReportProfileNotFoundError } from "../errors";
|
||||||
|
import type { ReportLocalization } from "../models";
|
||||||
import type {
|
import type {
|
||||||
ICompanyReportProfileFinder,
|
ICompanyReportProfileFinder,
|
||||||
IProformaFinder,
|
IProformaFinder,
|
||||||
IProformaFullReadModelAssembler,
|
IProformaFullReadModelAssembler,
|
||||||
ProformaDocumentGeneratorService,
|
ProformaDocumentGeneratorService,
|
||||||
} from "../services";
|
} from "../services";
|
||||||
import type { ReportLocalization } from "../models";
|
|
||||||
import type { IProformaFullSnapshotBuilder } from "../snapshot-builders";
|
import type { IProformaFullSnapshotBuilder } from "../snapshot-builders";
|
||||||
import type { IProformaReportSnapshotBuilder } from "../snapshot-builders/report";
|
import type { IProformaReportSnapshotBuilder } from "../snapshot-builders/report";
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ export class PreviewProformaReportUseCase {
|
|||||||
|
|
||||||
return this.deps.transactionManager.complete(async (transaction) => {
|
return this.deps.transactionManager.complete(async (transaction) => {
|
||||||
try {
|
try {
|
||||||
const proformaResult = await this.deps.finder.findProformaById(
|
const proformaResult = await this.deps.finder.findProformaByIdIncludingArchived(
|
||||||
companyId,
|
companyId,
|
||||||
proformaId,
|
proformaId,
|
||||||
transaction
|
transaction
|
||||||
|
|||||||
@ -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);
|
||||||
|
});
|
||||||
@ -1,15 +1,15 @@
|
|||||||
import type { ITransactionManager } from "@erp/core/api";
|
import type { ITransactionManager } from "@erp/core/api";
|
||||||
import { UniqueID } from "@repo/rdx-ddd";
|
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 { CompanyReportProfileNotFoundError } from "../errors";
|
||||||
|
import type { ReportLocalization } from "../models";
|
||||||
import type {
|
import type {
|
||||||
ICompanyReportProfileFinder,
|
ICompanyReportProfileFinder,
|
||||||
IProformaFinder,
|
IProformaFinder,
|
||||||
IProformaFullReadModelAssembler,
|
IProformaFullReadModelAssembler,
|
||||||
ProformaDocumentGeneratorService,
|
ProformaDocumentGeneratorService,
|
||||||
} from "../services";
|
} from "../services";
|
||||||
import type { ReportLocalization } from "../models";
|
|
||||||
import type { IProformaFullSnapshotBuilder } from "../snapshot-builders";
|
import type { IProformaFullSnapshotBuilder } from "../snapshot-builders";
|
||||||
import type { IProformaReportSnapshotBuilder } from "../snapshot-builders/report";
|
import type { IProformaReportSnapshotBuilder } from "../snapshot-builders/report";
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ export class ReportProformaPdfUseCase {
|
|||||||
|
|
||||||
return this.deps.transactionManager.complete(async (transaction) => {
|
return this.deps.transactionManager.complete(async (transaction) => {
|
||||||
try {
|
try {
|
||||||
const proformaResult = await this.deps.finder.findProformaById(
|
const proformaResult = await this.deps.finder.findProformaByIdIncludingArchived(
|
||||||
companyId,
|
companyId,
|
||||||
proformaId,
|
proformaId,
|
||||||
transaction
|
transaction
|
||||||
|
|||||||
@ -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<IDataSource, "custom">;
|
||||||
|
|
||||||
|
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,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
});
|
||||||
@ -17,8 +17,10 @@ export const unarchiveProformaById = (
|
|||||||
|
|
||||||
if (!proformaId) throw new Error("proformaId is required");
|
if (!proformaId) throw new Error("proformaId is required");
|
||||||
|
|
||||||
return dataSource.custom<UnarchiveProformaByIdResult>(`proformas/${proformaId}/unarchive`, {
|
return dataSource.custom<undefined, UnarchiveProformaByIdResult>({
|
||||||
method: "PATCH",
|
path: `proformas/${proformaId}/unarchive`,
|
||||||
|
method: "patch",
|
||||||
|
data: undefined,
|
||||||
signal,
|
signal,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user