- Implemented `usePaymentMethodUpdateMutation` for updating payment methods with validation. - Created settings controllers and hooks for managing payment methods. - Added UI components for creating, editing, deleting, and displaying payment methods. - Introduced error handling and feedback mechanisms for payment method operations. - Developed form schemas and utility functions for handling payment method data. - Established a new settings page for managing payment methods with appropriate loading and error states.
229 lines
5.3 KiB
TypeScript
229 lines
5.3 KiB
TypeScript
/// <reference types="node" />
|
|
|
|
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
|
|
import type { IModuleClient } from "@erp/core/client";
|
|
|
|
import { buildSettingsNavigation } from "./build-settings-navigation";
|
|
import { settingsSectionCatalog } from "./settings-section-catalog";
|
|
|
|
const createModule = (overrides: Partial<IModuleClient>): IModuleClient => {
|
|
return {
|
|
name: "TestModule",
|
|
version: "1.0.0",
|
|
...overrides,
|
|
};
|
|
};
|
|
|
|
test("ignora módulos sin settings", () => {
|
|
const result = buildSettingsNavigation({
|
|
modules: [
|
|
createModule({
|
|
name: "WithoutSettings",
|
|
}),
|
|
],
|
|
sections: settingsSectionCatalog,
|
|
});
|
|
|
|
assert.deepEqual(result, []);
|
|
});
|
|
|
|
test("recoge una entry de settings y la asocia a su sección", () => {
|
|
const result = buildSettingsNavigation({
|
|
modules: [
|
|
createModule({
|
|
name: "Customers",
|
|
settings: {
|
|
entries: [
|
|
{
|
|
id: "company-details",
|
|
sectionId: "company",
|
|
labelKey: "settings.company.details",
|
|
path: "/settings/company/details",
|
|
},
|
|
],
|
|
},
|
|
}),
|
|
],
|
|
sections: settingsSectionCatalog,
|
|
});
|
|
|
|
assert.deepEqual(result, [
|
|
{
|
|
id: "company",
|
|
labelKey: "web.settings.sections.company",
|
|
entries: [
|
|
{
|
|
id: "company-details",
|
|
sectionId: "company",
|
|
labelKey: "settings.company.details",
|
|
path: "/settings/company/details",
|
|
moduleName: "Customers",
|
|
},
|
|
],
|
|
},
|
|
]);
|
|
});
|
|
|
|
test("agrega entries de dos módulos en la misma sección", () => {
|
|
const result = buildSettingsNavigation({
|
|
modules: [
|
|
createModule({
|
|
name: "CustomerInvoices",
|
|
settings: {
|
|
entries: [
|
|
{
|
|
id: "verifactu",
|
|
sectionId: "billing",
|
|
labelKey: "settings.verifactu.title",
|
|
path: "/settings/billing/verifactu",
|
|
},
|
|
],
|
|
},
|
|
}),
|
|
createModule({
|
|
name: "DocumentSeries",
|
|
settings: {
|
|
entries: [
|
|
{
|
|
id: "document-series",
|
|
sectionId: "billing",
|
|
labelKey: "settings.documentSeries.title",
|
|
path: "/settings/billing/document-series",
|
|
},
|
|
],
|
|
},
|
|
}),
|
|
],
|
|
sections: settingsSectionCatalog,
|
|
});
|
|
|
|
assert.deepEqual(result, [
|
|
{
|
|
id: "billing",
|
|
labelKey: "web.settings.sections.billing",
|
|
entries: [
|
|
{
|
|
id: "verifactu",
|
|
sectionId: "billing",
|
|
labelKey: "settings.verifactu.title",
|
|
path: "/settings/billing/verifactu",
|
|
moduleName: "CustomerInvoices",
|
|
},
|
|
{
|
|
id: "document-series",
|
|
sectionId: "billing",
|
|
labelKey: "settings.documentSeries.title",
|
|
path: "/settings/billing/document-series",
|
|
moduleName: "DocumentSeries",
|
|
},
|
|
],
|
|
},
|
|
]);
|
|
});
|
|
|
|
test("incluye entries publicadas en la sección general", () => {
|
|
const result = buildSettingsNavigation({
|
|
modules: [
|
|
createModule({
|
|
name: "Catalogs",
|
|
settings: {
|
|
entries: [
|
|
{
|
|
id: "payment-methods",
|
|
sectionId: "general",
|
|
labelKey: "settings.paymentMethods.title",
|
|
path: "/settings/general/payment-methods",
|
|
},
|
|
],
|
|
},
|
|
}),
|
|
],
|
|
sections: settingsSectionCatalog,
|
|
});
|
|
|
|
assert.deepEqual(result, [
|
|
{
|
|
id: "general",
|
|
labelKey: "web.settings.sections.general",
|
|
entries: [
|
|
{
|
|
id: "payment-methods",
|
|
sectionId: "general",
|
|
labelKey: "settings.paymentMethods.title",
|
|
path: "/settings/general/payment-methods",
|
|
moduleName: "Catalogs",
|
|
},
|
|
],
|
|
},
|
|
]);
|
|
});
|
|
|
|
test("falla si un módulo declara una sección inexistente", () => {
|
|
assert.throws(
|
|
() =>
|
|
buildSettingsNavigation({
|
|
modules: [
|
|
createModule({
|
|
name: "BrokenModule",
|
|
settings: {
|
|
entries: [
|
|
{
|
|
id: "unknown",
|
|
sectionId: "unknown",
|
|
labelKey: "settings.unknown.title",
|
|
path: "/settings/unknown/item",
|
|
},
|
|
],
|
|
},
|
|
}),
|
|
],
|
|
sections: settingsSectionCatalog,
|
|
}),
|
|
/sección inexistente "unknown"/i
|
|
);
|
|
});
|
|
|
|
test("produce un resultado determinista", () => {
|
|
const modules = [
|
|
createModule({
|
|
name: "A",
|
|
settings: {
|
|
entries: [
|
|
{
|
|
id: "company-details",
|
|
sectionId: "company",
|
|
labelKey: "settings.company.details",
|
|
path: "/settings/company/details",
|
|
},
|
|
],
|
|
},
|
|
}),
|
|
createModule({
|
|
name: "B",
|
|
settings: {
|
|
entries: [
|
|
{
|
|
id: "verifactu",
|
|
sectionId: "billing",
|
|
labelKey: "settings.verifactu.title",
|
|
path: "/settings/billing/verifactu",
|
|
},
|
|
],
|
|
},
|
|
}),
|
|
];
|
|
|
|
const firstResult = buildSettingsNavigation({
|
|
modules,
|
|
sections: settingsSectionCatalog,
|
|
});
|
|
const secondResult = buildSettingsNavigation({
|
|
modules,
|
|
sections: settingsSectionCatalog,
|
|
});
|
|
|
|
assert.deepEqual(secondResult, firstResult);
|
|
});
|