Eigener Endpunkt und MCP-Tool ändern ausschließlich die Positionskostenstellen, auch bei gebuchten oder einer Bankbuchung zugewiesenen Eingangsbelegen. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
49 lines
2.0 KiB
TypeScript
49 lines
2.0 KiB
TypeScript
import assert from "node:assert/strict"
|
|
import test from "node:test"
|
|
import {
|
|
applyAccountCostCentreAssignments,
|
|
normalizeAccountCostCentreAssignments,
|
|
} from "../src/modules/incoming-invoice-cost-centres.service"
|
|
import { mcpToolMap } from "../src/mcp/registry"
|
|
|
|
const CENTRE = "8f1c2b3a-4d5e-4f60-8a7b-9c0d1e2f3a4b"
|
|
|
|
test("changes only requested account cost centres", () => {
|
|
const accounts = [
|
|
{ account: 1, amountNet: 100, taxType: "19", costCentre: "old-1" },
|
|
{ account: 2, amountNet: 50, taxType: "7", costCentre: "old-2" },
|
|
]
|
|
|
|
assert.deepEqual(applyAccountCostCentreAssignments(accounts, [
|
|
{ index: 1, costcentre: CENTRE },
|
|
]), [
|
|
accounts[0],
|
|
{ account: 2, amountNet: 50, taxType: "7", costCentre: CENTRE },
|
|
])
|
|
})
|
|
|
|
test("rejects assignments for unknown invoice positions", () => {
|
|
assert.throws(
|
|
() => applyAccountCostCentreAssignments([{ account: 1 }], [{ index: 3, costcentre: null }]),
|
|
/Position 4.*nicht gefunden/,
|
|
)
|
|
})
|
|
|
|
test("validates cost centre assignments", () => {
|
|
assert.throws(() => normalizeAccountCostCentreAssignments([]), /Mindestens eine/)
|
|
assert.throws(() => normalizeAccountCostCentreAssignments([{ index: -1, costcentre: null }]), /gültigen index/)
|
|
assert.throws(() => normalizeAccountCostCentreAssignments([{ index: 0, costcentre: "x" }]), /Ungültige Kostenstelle/)
|
|
assert.throws(
|
|
() => normalizeAccountCostCentreAssignments([{ index: 0, costcentre: null }, { index: 0, costcentre: CENTRE }]),
|
|
/mehrfach/,
|
|
)
|
|
assert.deepEqual(normalizeAccountCostCentreAssignments([{ index: 0, costcentre: CENTRE }]), [{ index: 0, costcentre: CENTRE }])
|
|
})
|
|
|
|
test("registers a dedicated incoming invoice cost centre tool", () => {
|
|
const tool = mcpToolMap.get("accounting.incoming_invoices.cost_centres.update")
|
|
|
|
assert.deepEqual(tool?.requiredPermissions, ["accounting.incoming_invoices.write"])
|
|
assert.deepEqual(tool?.inputSchema.required, ["id", "accountCostCentres"])
|
|
})
|