Files
FEDEO/backend/tests/tenantExportGlobalResources.test.ts
flfeders f375d63655
All checks were successful
Build and Push Docker Images / build-backend (push) Successful in 39s
Build and Push Docker Images / build-frontend (push) Successful in 25s
Build and Push Docker Images / build-website (push) Successful in 24s
Build and Push Docker Images / build-central-services-api (push) Successful in 24s
Build and Push Docker Images / build-central-services-admin (push) Successful in 25s
Build and Push Docker Images / build-docs (push) Successful in 24s
Include global resources in tenant exports
2026-08-06 11:11:31 +02:00

53 lines
1.8 KiB
TypeScript

import assert from "node:assert/strict"
import test from "node:test"
import { addTenantExportGlobalResources } from "../src/utils/tenantExportGlobalResources"
test("adds global resources and the tenant account chart to a tenant export", async () => {
const tables: Record<string, Record<string, any>[]> = {}
const calls: { table: string, whereSql: string, params?: any[] }[] = []
const rowsByTable: Record<string, Record<string, any>[]> = {
units: [{ id: 1, name: "Monat" }],
citys: [{ id: 1, zip: 26316 }],
countrys: [{ id: 1, name: "Deutschland" }],
accounts: [{ id: 1, accountChart: "skr04", number: "4400" }],
}
await addTenantExportGlobalResources(
tables,
new Set(Object.keys(rowsByTable)),
{ id: 42, accountChart: "skr04" },
async (table, whereSql, params) => {
calls.push({ table, whereSql, params })
return rowsByTable[table]
},
(target, table, rows) => {
target[table] = rows
}
)
assert.deepEqual(tables, rowsByTable)
assert.deepEqual(calls, [
{ table: "units", whereSql: "true", params: undefined },
{ table: "citys", whereSql: "true", params: undefined },
{ table: "countrys", whereSql: "true", params: undefined },
{ table: "accounts", whereSql: `"accountChart" = $1`, params: ["skr04"] },
])
})
test("skips global tables that do not exist in an older database schema", async () => {
const tables: Record<string, Record<string, any>[]> = {}
await addTenantExportGlobalResources(
tables,
new Set(["units"]),
{ id: 42 },
async () => [{ id: 1, name: "Stück" }],
(target, table, rows) => {
target[table] = rows
}
)
assert.deepEqual(tables, { units: [{ id: 1, name: "Stück" }] })
})