Add tenant merge dry-run planner
This commit is contained in:
56
backend/tests/tenantMergePlan.test.ts
Normal file
56
backend/tests/tenantMergePlan.test.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import assert from "node:assert/strict"
|
||||
import test from "node:test"
|
||||
|
||||
import { buildTenantMergePlan } from "../src/utils/tenantMergePlan"
|
||||
|
||||
test("classifies imports, existing rows, conflicts and global id collisions", () => {
|
||||
const plan = buildTenantMergePlan({
|
||||
units: [
|
||||
{ id: 1, name: "Stück", short: "Stk." },
|
||||
{ id: 2, name: "Monat", short: "Mon." },
|
||||
{ id: 3, name: "Stunde", short: "Std." },
|
||||
],
|
||||
customers: [
|
||||
{ id: 10, tenant: 42, name: "Neu" },
|
||||
{ id: 11, tenant: 42, name: "Geändert" },
|
||||
],
|
||||
}, {
|
||||
units: [
|
||||
{ id: 1, name: "Stück", short: "Stk.", updated_at: "later" },
|
||||
{ id: 2, name: "Kilometer", short: "km" },
|
||||
{ id: 9, name: "Stunde", short: "h" },
|
||||
],
|
||||
customers: [
|
||||
{ id: 11, tenant: 42, name: "Zieländerung" },
|
||||
],
|
||||
}, {
|
||||
units: { primaryKey: ["id"] },
|
||||
customers: { primaryKey: ["id"] },
|
||||
})
|
||||
|
||||
assert.deepEqual(plan.summary, {
|
||||
import: 1,
|
||||
existing: 1,
|
||||
conflict: 2,
|
||||
id_collision: 1,
|
||||
})
|
||||
|
||||
assert.equal(plan.items.find((item) => item.label === "Monat")?.kind, "id_collision")
|
||||
assert.equal(plan.items.find((item) => item.label === "Stunde")?.kind, "conflict")
|
||||
assert.equal(plan.items.find((item) => item.label === "Geändert")?.defaultDecision, "target")
|
||||
})
|
||||
|
||||
test("uses target as the safe default for two-way conflicts", () => {
|
||||
const plan = buildTenantMergePlan({
|
||||
accounts: [{ id: 5, accountChart: "skr03", number: "8400", label: "Quelle" }],
|
||||
}, {
|
||||
accounts: [{ id: 99, accountChart: "skr03", number: "8400", label: "Ziel" }],
|
||||
}, {
|
||||
accounts: { primaryKey: ["id"] },
|
||||
})
|
||||
|
||||
assert.equal(plan.items[0].kind, "conflict")
|
||||
assert.equal(plan.items[0].targetKey, "id=99")
|
||||
assert.equal(plan.items[0].defaultDecision, "target")
|
||||
assert.deepEqual(plan.items[0].differences.sort(), ["id", "label"])
|
||||
})
|
||||
Reference in New Issue
Block a user