- Created node-check.log to capture Node.js syntax errors. - Added proxy.log for TLS termination diagnostics. - Introduced rdx-ui-types.log and resources-types.log for TypeScript compilation logs. - Implemented resources.log to log test results for various resource-related tests. - Added table.log to log column restoration and preference isolation tests. - Created types.log to log type checking results across multiple packages. - Added web-types.log for TypeScript compilation logs specific to web components. - Introduced traceability.json to track changes in recorded sources and their states. - Implemented infrastructure-items.ts to retrieve infrastructure items with roles and interfaces. - Added company-people-navigation.tsx for navigation in company detail views.
182 lines
6.4 KiB
TypeScript
182 lines
6.4 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import { test } from "node:test";
|
|
|
|
import { UniqueID } from "@repo/rdx-ddd";
|
|
import { Maybe } from "@repo/rdx-utils";
|
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
import { createInstance } from "i18next";
|
|
import { renderToStaticMarkup } from "react-dom/server";
|
|
import { I18nextProvider } from "react-i18next";
|
|
|
|
import { buildCatalogResponse } from "../../../api/application/asset-catalog-response.builder";
|
|
import { AssetCatalog } from "../../../api/domain/asset-catalog.aggregate";
|
|
import { seedAssetCatalog } from "../../../api/domain/asset-catalog-seed";
|
|
import { InfrastructureValues } from "../../../api/domain/value-objects/infrastructure-values.vo";
|
|
import { InfrastructureSchema } from "../../../common/infrastructure";
|
|
import { AssetSchema } from "../../../common/inventory";
|
|
import { catalogKeys } from "../../catalog/shared/api";
|
|
import { assetsEnglish, assetsSpanish } from "../../shared";
|
|
import { inventoryKeys } from "../../shared/queries";
|
|
import { InfrastructurePage } from "../list/ui/infrastructure-page";
|
|
|
|
import { infrastructureKeys } from "./api/infrastructure-api";
|
|
import { getInfrastructureItems } from "./helpers/infrastructure-items";
|
|
import { infrastructureRoles } from "./helpers/infrastructure-roles";
|
|
import { AssetInfrastructurePanel } from "./ui/asset-infrastructure-panel";
|
|
|
|
const companyId = UniqueID.generateNewID().toPrimitive();
|
|
const catalog = buildCatalogResponse(seedAssetCatalog(AssetCatalog.create()), Maybe.none());
|
|
const router = catalog.items.find((item) => item.builtinKey === "template:router");
|
|
|
|
assert.ok(router && router.values.kind === "template");
|
|
const templateId = router.id;
|
|
const values = {
|
|
name: "Router principal",
|
|
templateId,
|
|
siteId: null,
|
|
status: "operational",
|
|
notes: "",
|
|
characteristics: {},
|
|
};
|
|
const asset = AssetSchema.parse({
|
|
id: UniqueID.generateNewID().toPrimitive(),
|
|
companyId,
|
|
values,
|
|
assigned: false,
|
|
displayStatus: "available",
|
|
specification: {
|
|
templateId,
|
|
templateName: "Router",
|
|
fields: [
|
|
{
|
|
fieldId: UniqueID.generateNewID().toPrimitive(),
|
|
name: "Modelo",
|
|
type: "text",
|
|
unit: "",
|
|
choices: [],
|
|
required: false,
|
|
},
|
|
],
|
|
},
|
|
history: [
|
|
{
|
|
id: UniqueID.generateNewID().toPrimitive(),
|
|
values,
|
|
actorId: UniqueID.generateNewID().toPrimitive(),
|
|
actorName: "Técnico",
|
|
recordedAt: "2026-10-17T10:00:00.000Z",
|
|
},
|
|
],
|
|
});
|
|
const networkValues = InfrastructureValues.create({
|
|
roles: ["network"],
|
|
interfaces: [
|
|
{
|
|
name: "LAN",
|
|
kind: "ethernet",
|
|
mac: "",
|
|
notes: "",
|
|
addresses: [{ address: "192.168.5.201" }],
|
|
},
|
|
{ name: "Wi-Fi", kind: "wifi", mac: "", notes: "", addresses: [{ address: "192.168.5.202" }] },
|
|
],
|
|
});
|
|
|
|
assert.ok(networkValues.isSuccess);
|
|
const snapshot = networkValues.data.toPrimitive();
|
|
const config = InfrastructureSchema.parse({
|
|
id: UniqueID.generateNewID().toPrimitive(),
|
|
assetId: asset.id,
|
|
companyId,
|
|
values: snapshot,
|
|
history: [
|
|
{
|
|
id: UniqueID.generateNewID().toPrimitive(),
|
|
actorId: UniqueID.generateNewID().toPrimitive(),
|
|
actorName: "Técnico",
|
|
recordedAt: "2026-10-17T10:00:00.000Z",
|
|
values: snapshot,
|
|
},
|
|
],
|
|
});
|
|
|
|
test("infraestructura: clasificación de serie independiente del nombre/icono y selección manual prioritaria", () => {
|
|
assert.ok(router.values.kind === "template");
|
|
const renamed = {
|
|
...router,
|
|
values: { ...router.values, name: "Nombre propio", icon: "box" as const },
|
|
};
|
|
|
|
assert.deepEqual(infrastructureRoles(templateId, [renamed]), ["network"]);
|
|
assert.deepEqual(
|
|
infrastructureRoles(templateId, [renamed], {
|
|
...config,
|
|
values: { ...config.values, roles: ["storage"] },
|
|
}),
|
|
["storage"]
|
|
);
|
|
assert.deepEqual(infrastructureRoles(templateId, [{ ...renamed, builtinKey: null }]), []);
|
|
});
|
|
|
|
test("infraestructura: el total incluye roles e interfaces, respeta exclusiones manuales y no duplica activos", () => {
|
|
assert.equal(getInfrastructureItems([], catalog.items, []).length, 0);
|
|
assert.equal(getInfrastructureItems([asset], catalog.items, []).length, 1);
|
|
assert.equal(getInfrastructureItems([asset], catalog.items, [config]).length, 1);
|
|
assert.equal(getInfrastructureItems([asset], [], []).length, 0);
|
|
const interfacesOnly = { ...config, values: { ...config.values, roles: [] } };
|
|
const excluded = { ...config, values: { ...config.values, roles: [], interfaces: [] } };
|
|
|
|
assert.equal(getInfrastructureItems([asset], [], [interfacesOnly]).length, 1);
|
|
assert.equal(getInfrastructureItems([asset], catalog.items, [excluded]).length, 0);
|
|
assert.equal(getInfrastructureItems([asset], [], [{ ...config, assetId: companyId }]).length, 0);
|
|
});
|
|
|
|
test("infraestructura: listado y ficha presentan interfaces/IP en español e inglés, sin puertos", async () => {
|
|
for (const [language, title, edit] of [
|
|
["es", "Infraestructura", "Editar infraestructura"],
|
|
["en", "Infrastructure", "Edit infrastructure"],
|
|
] as const) {
|
|
const i18n = createInstance();
|
|
|
|
await i18n.init({
|
|
lng: language,
|
|
resources: { es: { assets: assetsSpanish }, en: { assets: assetsEnglish } },
|
|
});
|
|
const client = new QueryClient();
|
|
|
|
client.setQueryData(catalogKeys.scope(companyId), catalog);
|
|
client.setQueryData(inventoryKeys.company(companyId), {
|
|
assets: [asset],
|
|
workstations: [],
|
|
relationships: [],
|
|
});
|
|
client.setQueryData(infrastructureKeys.company(companyId), { items: [config] });
|
|
try {
|
|
const html = renderToStaticMarkup(
|
|
<QueryClientProvider client={client}>
|
|
<I18nextProvider i18n={i18n}>
|
|
<InfrastructurePage companyId={companyId} />
|
|
<AssetInfrastructurePanel
|
|
assetId={asset.id}
|
|
assetName={asset.values.name}
|
|
companyId={companyId}
|
|
templateId={templateId}
|
|
/>
|
|
</I18nextProvider>
|
|
</QueryClientProvider>
|
|
);
|
|
|
|
assert.ok(html.includes(title));
|
|
assert.ok(html.includes(edit));
|
|
assert.ok(html.includes("192.168.5.201"));
|
|
assert.ok(html.includes("192.168.5.202"));
|
|
assert.ok(html.includes("Wi-Fi"));
|
|
assert.ok(html.includes(`/companies/${companyId}/assets/${asset.id}`));
|
|
assert.ok(html.includes('aria-haspopup="dialog"'));
|
|
assert.equal(html.includes("infrastructure.roles.network"), false);
|
|
} finally {
|
|
client.clear();
|
|
}
|
|
}
|
|
});
|